CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    read write lock in C#

    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

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: read write lock in C#

    Read the documentation page for ReaderWriterLock and it'll explain the possible errors and also tell you what is/isn't allowed.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: read write lock in C#

    Thanks Mutant_Fruit,


    Quote Originally Posted by Mutant_Fruit
    Read the documentation page for ReaderWriterLock and it'll explain the possible errors and also tell you what is/isn't allowed.
    1.

    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?

    2.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured