Skip to content

Instantly share code, notes, and snippets.

@ronnieoverby
Created May 20, 2015 21:04
Show Gist options
  • Select an option

  • Save ronnieoverby/59b715c3676127a113c3 to your computer and use it in GitHub Desktop.

Select an option

Save ronnieoverby/59b715c3676127a113c3 to your computer and use it in GitHub Desktop.
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