Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created November 1, 2011 14:08
Show Gist options
  • Save kumpera/1330573 to your computer and use it in GitHub Desktop.
Save kumpera/1330573 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Threading;
namespace RWLockSlimTest
{
class MainClass
{
public static void Main(string[] args)
{
ReaderWriterLockSlim rwlock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
rwlock.EnterWriteLock ();
rwlock.EnterUpgradeableReadLock ();
rwlock.ExitUpgradeableReadLock ();
rwlock.ExitWriteLock ();
/* The next statement fails with
Unhandled Exception: System.Threading.LockRecursionException: In read mode you can just enter Read recursively
at System.Threading.ReaderWriterLockSlim.CheckRecursionAuthorization (LockState ctstate, LockState desiredState) [0x00000] in <filename unknown>:0
at System.Threading.ReaderWriterLockSlim.CheckState (System.Threading.ThreadLockState state, Int32 millisecondsTimeout, LockState validState) [0x00000] in <filename unknown>:0
at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (Int32 millisecondsTimeout) [0x00000] in <filename unknown>:0
at System.Threading.ReaderWriterLockSlim.EnterWriteLock () [0x00000] in <filename unknown>:0
at RWLockSlimTest.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
*/
rwlock.EnterWriteLock ();
//rwlock.ExitWriteLock ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment