Avatar of gustierng
gustierng
 asked on

ReaderWriterLock.AcquireReaderLock takes too long to hit

Hi

I am using a ReaderWriterLock on a .net remoting server, when I put a break point on the line: ReaderWriterLock.AcquireReaderLock, it takes about 1 minute to hit this break point because the writes are very frequent.  Is there a way to get this lock on so hat the reads have a higher priority.  There seems to be several functions for releasing and upgrading locks, but not sure how to use them.

Thank you
C#

Avatar of undefined
Last Comment
gustierng

8/22/2022 - Mon
MogalManic

Do you have only one writer?

Here is what I MSDN docs says (http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlock.aspx):
   Readers and writers are queued separately. When a thread releases the writer lock,
   all threads waiting in the reader queue at that instant are granted reader locks; when 
   all of those reader locks have been released, the next thread waiting in the writer 
   queue, if any, is granted the writer lock, and so on. In other words, ReaderWriterLock 
   alternates between a collection of readers, and one writer.

Open in new window



gustierng

ASKER
actually I have raised the priority of the reads and made the writes into background tasks
MogalManic

If you have multiple threads reading AND writing to your resource, you might want to just use a simple lock {} mechanism instead of using ReaderWriterLock.

What might be happening is multiple write threads are getting queued up and only a small number of reader threads are being processed.  So the locking is spending most of its time processing the Writer queue.

If you just use a simple lock, then readers and writers get the same preference.  
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
MogalManic

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gustierng

ASKER
thanks