Created
May 20, 2015 21:04
-
-
Save ronnieoverby/59b715c3676127a113c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Main() | |
| { | |
| using(var l = new ReaderWriterLockSlim()) | |
| { | |
| var tasks = Enumerable.Range(0,2).Select (i => | |
| Task.Run(() => | |
| { | |
| l.EnterUpgradeableReadLock(); | |
| try | |
| { | |
| Console.WriteLine("Task {0} has entered the lock.", i); | |
| while (true) Thread.Sleep(int.MaxValue); | |
| } | |
| finally | |
| { | |
| l.ExitUpgradeableReadLock(); | |
| } | |
| })).ToArray(); | |
| Task.WaitAll(tasks); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment