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:
- reader lock, then reader lock –>
LockRecursionException - reader lock, then upgradeable reader lock –>
LockRecursionException - reader lock, then writer lock –>
LockRecursionException - upgradeable reader lock, then reader lock –> no exception
- upgradeable reader lock, then upgradeable reader lock –>
LockRecursionException - upgradeable reader lock, then writer lock –> no exception
- writer lock, then reader lock –>
LockRecursionException - writer lock, then upgradeable reader lock –>
LockRecursionException - writer lock, then writer lock –>
LockRecursionException
Is this behavior correct?
From the docs:
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 🙂