473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ReaderWriterLock appears to contain a deadlock

Issue:
I have 3 threads, syncing with a ReaderWriterLock (in "real life", there
will be more).

Thread 1 (there could be any number of these) Gets a read lock with infinite
timeout. It runs in a loop. The readlocks are requested and released very
often.

Thread 2 (only one, this is my deadlock testing thread) represents a longer
running process. It gets a ReadLock as well.

(so far the world is good)

Thread 3 (timer thread, there will only ever be one of these) requests a
Write Lock with a 5 second timeout.

Thread 3 fails to get the WriteLock ApplicationException is thrown. This is
expected behavior as well -- the purpose of the test is to force the
writelock to time out.

Now here's the part that looks like a bug:
Even though Thread 3 failed to acquire the lock, the ReaderWriter stops
handing out Readlocks -- just like it would if the write lock were in force.
It does not resume handing out readlocks until Thread 2 releases its
readlock (presumably this frees an internal deadlock on the readerwriter
lock, allowing it to clear the failed write lock).

My problem: Using timeouts on ReaderWriterLocks appears to be a useless
gesture, as it appears to leave the structure in an unstable state.
Further, since the timeouts don't work, I'm left with a potential deadlock
in my applicaiton.

Have I got something wrong here, or is there a problem?


Nov 15 '05 #1
3 4002
I have a Application that work almost in the same way, with N readers and N Writers (because the list of clients it's dynamic, and the use of the application too), in any moment, and for now the 2 work well, I have that the writers timeout in 5 seconds.
--
Bela Istok
MVP C#
Caracas, Venezuela
"J.Marsch" <je****@ctcdeveloper.com> wrote in message news:uf**************@tk2msftngp13.phx.gbl...
Issue:
I have 3 threads, syncing with a ReaderWriterLock (in "real life", there
will be more).

Thread 1 (there could be any number of these) Gets a read lock with infinite
timeout. It runs in a loop. The readlocks are requested and released very
often.

Thread 2 (only one, this is my deadlock testing thread) represents a longer
running process. It gets a ReadLock as well.

(so far the world is good)

Thread 3 (timer thread, there will only ever be one of these) requests a
Write Lock with a 5 second timeout.

Thread 3 fails to get the WriteLock ApplicationException is thrown. This is
expected behavior as well -- the purpose of the test is to force the
writelock to time out.

Now here's the part that looks like a bug:
Even though Thread 3 failed to acquire the lock, the ReaderWriter stops
handing out Readlocks -- just like it would if the write lock were in force.
It does not resume handing out readlocks until Thread 2 releases its
readlock (presumably this frees an internal deadlock on the readerwriter
lock, allowing it to clear the failed write lock).

My problem: Using timeouts on ReaderWriterLocks appears to be a useless
gesture, as it appears to leave the structure in an unstable state.
Further, since the timeouts don't work, I'm left with a potential deadlock
in my applicaiton.

Have I got something wrong here, or is there a problem?


Nov 15 '05 #2
Have you ever forced a timeout to occur (by holding a lock). Mine works great as long as you never actually timeout.
"Bela Istok" <be****@hotmail.com> wrote in message news:et**************@TK2MSFTNGP11.phx.gbl...
I have a Application that work almost in the same way, with N readers and N Writers (because the list of clients it's dynamic, and the use of the application too), in any moment, and for now the 2 work well, I have that the writers timeout in 5 seconds.
--
Bela Istok
MVP C#
Caracas, Venezuela
"J.Marsch" <je****@ctcdeveloper.com> wrote in message news:uf**************@tk2msftngp13.phx.gbl...
Issue:
I have 3 threads, syncing with a ReaderWriterLock (in "real life", there
will be more).

Thread 1 (there could be any number of these) Gets a read lock with infinite
timeout. It runs in a loop. The readlocks are requested and released very
often.

Thread 2 (only one, this is my deadlock testing thread) represents a longer
running process. It gets a ReadLock as well.

(so far the world is good)

Thread 3 (timer thread, there will only ever be one of these) requests a
Write Lock with a 5 second timeout.

Thread 3 fails to get the WriteLock ApplicationException is thrown. This is
expected behavior as well -- the purpose of the test is to force the
writelock to time out.

Now here's the part that looks like a bug:
Even though Thread 3 failed to acquire the lock, the ReaderWriter stops
handing out Readlocks -- just like it would if the write lock were in force.
It does not resume handing out readlocks until Thread 2 releases its
readlock (presumably this frees an internal deadlock on the readerwriter
lock, allowing it to clear the failed write lock).

My problem: Using timeouts on ReaderWriterLocks appears to be a useless
gesture, as it appears to leave the structure in an unstable state.
Further, since the timeouts don't work, I'm left with a potential deadlock
in my applicaiton.

Have I got something wrong here, or is there a problem?


Nov 15 '05 #3
I do a little test App to try: and i guest good results:

Enter: Fast Reader A0
Leave: Fast Reader A0
Enter: 10 sec Reader B0
Enter: 5 sec Wait Writer0
Enter: 5 sec Wait Writer1
Enter: 5 sec Wait Writer2
Enter: 5 sec Wait Writer3
Enter: 5 sec Wait Writer4
Enter: 5 sec Wait Writer5
Enter: 5 sec Wait Writer6
Enter: 5 sec Wait Writer7
Enter: 5 sec Wait Writer8
Enter: 5 sec Wait Writer9
Leave: 5 sec Wait Writer0
Leave: 5 sec Wait Writer1
Leave: 5 sec Wait Writer2
Leave: 5 sec Wait Writer3
Leave: 5 sec Wait Writer4
Leave: 5 sec Wait Writer5
Leave: 5 sec Wait Writer6
Leave: 5 sec Wait Writer7
Leave: 5 sec Wait Writer8
Leave: 5 sec Wait Writer9
Enter: Fast Reader A1
Leave: Fast Reader A1
Enter: 10 sec Reader B1
Enter: Fast Reader A2
Leave: Fast Reader A2
Enter: 10 sec Reader B2
Enter: Fast Reader A3
Leave: Fast Reader A3
Enter: 10 sec Reader B3
Enter: Fast Reader A4
Leave: Fast Reader A4
Enter: 10 sec Reader B4
Enter: Fast Reader A5
Leave: Fast Reader A5
Enter: 10 sec Reader B5
Enter: Fast Reader A6
Leave: Fast Reader A6
Enter: 10 sec Reader B6
Enter: Fast Reader A7
Leave: Fast Reader A7
Enter: 10 sec Reader B7
Enter: Fast Reader A8
Leave: Fast Reader A8
Enter: 10 sec Reader B8
Enter: Fast Reader A9
Leave: Fast Reader A9
Enter: 10 sec Reader B9
Leave: 10 sec Reader B0
Leave: 10 sec Reader B1
Leave: 10 sec Reader B2
Leave: 10 sec Reader B3
Leave: 10 sec Reader B4
Leave: 10 sec Reader B5
Leave: 10 sec Reader B6
Leave: 10 sec Reader B7
Leave: 10 sec Reader B8
Leave: 10 sec Reader B9

--
Bela Istok
MVP C#
Caracas, Venezuela
"J.Marsch" <je****@ctcdeveloper.com> wrote in message news:OQ**************@TK2MSFTNGP09.phx.gbl...
Have you ever forced a timeout to occur (by holding a lock). Mine works great as long as you never actually timeout.
"Bela Istok" <be****@hotmail.com> wrote in message news:et**************@TK2MSFTNGP11.phx.gbl...
I have a Application that work almost in the same way, with N readers and N Writers (because the list of clients it's dynamic, and the use of the application too), in any moment, and for now the 2 work well, I have that the writers timeout in 5 seconds.
--
Bela Istok
MVP C#
Caracas, Venezuela
"J.Marsch" <je****@ctcdeveloper.com> wrote in message news:uf**************@tk2msftngp13.phx.gbl...
Issue:
I have 3 threads, syncing with a ReaderWriterLock (in "real life", there
will be more).

Thread 1 (there could be any number of these) Gets a read lock with infinite
timeout. It runs in a loop. The readlocks are requested and released very
often.

Thread 2 (only one, this is my deadlock testing thread) represents a longer
running process. It gets a ReadLock as well.

(so far the world is good)

Thread 3 (timer thread, there will only ever be one of these) requests a
Write Lock with a 5 second timeout.

Thread 3 fails to get the WriteLock ApplicationException is thrown. This is
expected behavior as well -- the purpose of the test is to force the
writelock to time out.

Now here's the part that looks like a bug:
Even though Thread 3 failed to acquire the lock, the ReaderWriter stops
handing out Readlocks -- just like it would if the write lock were in force.
It does not resume handing out readlocks until Thread 2 releases its
readlock (presumably this frees an internal deadlock on the readerwriter
lock, allowing it to clear the failed write lock).

My problem: Using timeouts on ReaderWriterLocks appears to be a useless
gesture, as it appears to leave the structure in an unstable state.
Further, since the timeouts don't work, I'm left with a potential deadlock
in my applicaiton.

Have I got something wrong here, or is there a problem?


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
3
by: Nigel Robbins | last post by:
Hi There, I'm getting a deadlock when I have two clients running the following statement. DELETE FROM intermediate.file_os_details WHERE file_uid = ? AND obj_uid There is a compound index on...
2
by: pokémon | last post by:
Question: Is this thread-safe: ReaderWriterLock rwl = new ReaderWriterLock(); Queue q = new Queue(); public int GetCount() { int val = 0; try {
2
by: Tryion | last post by:
Hi, I'd like to know if it's possible/responsible to use the ReaderWriterLock class (RWL) in a class without declaring it as "static". The example in the SDK does not use a static RWL. However,...
0
by: Qingdong Z. | last post by:
I have a public shared DateTime type variable called . There are multiple work threads updating this variable to current time (Now). Normally, the DateTime variable is updated 10-100 times per...
6
by: Itay | last post by:
Hi , Is there a way to lock several ReaderWriterLock in an atomic manner? I have numerous amount of ReaderWriterLock objects and I need to lock some of them for reading only, is there a way...
4
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an unhandled exception if I acquire a WriterLock with...
7
by: Julie | last post by:
According to the documentation for the Acquire methods on the ReaderWriterLock class: -1 Infinite. 0 No time-out. > 0 The number of milliseconds to wait. ...
1
by: fm | last post by:
I have a public shared property in global.asax. When the variable of the property is not instantiated (first page to call it, cache empties, etc.) the code then loads the variable from source...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.