Reputation: 15623
Concerning the ReaderWriterLockSlim
:
Acquiring two locks subsequently within the same thread should actually throw a LockRecursionException
(the recursion policy is set to NoRecursion
).
My observation results:
LockRecursionException
LockRecursionException
LockRecursionException
LockRecursionException
LockRecursionException
LockRecursionException
LockRecursionException
Is this behavior correct?
Upvotes: 4
Views: 919
Reputation: 5706
A thread in upgradeable mode can downgrade to read mode by first calling the
EnterReadLock
method and then calling theExitUpgradeableReadLock
method. This downgrade pattern is allowed for all lock recursion policies, evenNoRecursion
.
My understanding is that for the writing situation, entering a write lock is the normal way to move from upgradeable to write mode anyway, so has to be supported even under a policy of NoRecursion
(there would seem to be little point to a non-upgradeable upgradeable lock :)
Upvotes: 4