Is ReaderWriterLockSlim.EnterUpgradeableReadLock() essentially the same as Monitor.Enter()?

Posted by Neil Barnwell on Stack Overflow See other posts from Stack Overflow or by Neil Barnwell
Published on 2010-04-30T14:50:03Z Indexed on 2010/04/30 15:27 UTC
Read the original article Hit count: 245

So I have a situation where I may have many, many reads and only the occasional write to a resource shared between multiple threads.

A long time ago I read about ReaderWriterLock, and have read about ReaderWriterGate which attempts to mitigate the issue where many writes coming in trump reads and hurt performance. However, now I've become aware of ReaderWriterLockSlim...

From the docs, I believe that there can only be one thread in "upgradeable mode" at any one time. In a situation where the only access I'm using is EnterUpgradeableReadLock() (which is appropriate for my scenario) then is there much difference to just sticking with lock(){}?

Here's the excerpt:

A thread that tries to enter upgradeable mode blocks if there is already a thread in upgradeable mode, if there are threads waiting to enter write mode, or if there is a single thread in write mode.

Or, does the recursion policy make any difference to this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about readerwriterlockslim