473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ReaderWriterLoc k appears to contain a deadlock

Issue:
I have 3 threads, syncing with a ReaderWriterLoc k (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 ApplicationExce ption 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 ReaderWriterLoc ks 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 4011
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****@ctcdeve loper.com> wrote in message news:uf******** ******@tk2msftn gp13.phx.gbl...
Issue:
I have 3 threads, syncing with a ReaderWriterLoc k (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 ApplicationExce ption 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 ReaderWriterLoc ks 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******** ******@TK2MSFTN GP11.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****@ctcdeve loper.com> wrote in message news:uf******** ******@tk2msftn gp13.phx.gbl...
Issue:
I have 3 threads, syncing with a ReaderWriterLoc k (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 ApplicationExce ption 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 ReaderWriterLoc ks 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****@ctcdeve loper.com> wrote in message news:OQ******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP11.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****@ctcdeve loper.com> wrote in message news:uf******** ******@tk2msftn gp13.phx.gbl...
Issue:
I have 3 threads, syncing with a ReaderWriterLoc k (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 ApplicationExce ption 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 ReaderWriterLoc ks 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
9191
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 a table (c) re-queries another table using a subquery which references the inserted table (correlated or not)
3
7619
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 file_uid / obj_uid. The isolation level is UR and I have set DB2_RR_TO_RS=YES. Any thoughts why I'm getting the deadlock ?
2
3284
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
1714
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, the documentation has the standard disclaimer of "Any public static members of this type are safe for multithreaded operations. Any instance...
0
1949
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 second by work thread(s). The Main thread will read the variable value every three seconds. If the variable was not updated for 10 seconds, the main thread...
6
2145
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 doing it one shot ? Itay.
4
5497
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 a timeout less than the time required to process the code section it protects. The code listed below is just a small application I wrote to check...
7
2760
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. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingreaderwriterlockclasstopic.asp Does someone want to explain to me the difference...
1
1457
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 (web service, database, file, etc.) What I want to do is prevent many simultaneous users access this property when it's variable is not instantiated...
0
7479
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7411
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7669
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7926
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7439
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4962
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3468
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.