Skip to content

Read write lock in C#

George George

Asked Apr 16, 2008, 7:02 AM EDT1 answer
Share
LinkedInX

Hello everyone,


If I am using the ReaderWriterLock class, in the following 3 situations, except performance degrade, are there any functional issues? E.g. deadlock?

1. Acquire a specific write/read lock, and then acquire the write/read lock again, but release the write/read lock twice;

2. Acquire a specific read lock, and then acquire the write lock for the same object, and release in reverse order write lock, then read lock;

3. Acquire a specific write lock, and then acquire the read lock for the same object, and release in reverse order read lock, then write lock.


thanks in advance,
George

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    Thanks Matthew,

     

    Two more questions,

     

    1.

    What mean an immutable object or using an async model in your comments? Could you describe or give some links to study please?


    2.

    I have read the document, the issue is, when a thread acquire a read lock, and then upgrade to write lock, the thread is not ensured to continue to hold the lock and proceed executuion, since it will be appended to the end of the write lock queue, and in this scenario a thread which waits for read lock will be awaked, and the awaked thread will hold read lock? Right?

    So, if I want a thread to proceed execution and hold lock all the time, I need to let it own write lock at first, other than upgrade?

     

     

    regards,

    George

    0