Skip to content

Instantly share code, notes, and snippets.

@mirasrael
Created April 15, 2022 08:58
Show Gist options
  • Save mirasrael/6cec659ab0d5e6b0d120fe6ebc684ecf to your computer and use it in GitHub Desktop.
Save mirasrael/6cec659ab0d5e6b0d120fe6ebc684ecf to your computer and use it in GitHub Desktop.
Read Write Lock
public class Sample
{
ReadWriteLockSlim rwLock;
int counter;
public void IncrementTwice()
{
rwLock.EnterWriteLock();
try
{
counter = counter + 1;
counter = counter + 1;
}
finally
{
rwLock.ExitWriteLock();
}
}
public int Get()
{
rwLock.EnterReadLock();
try
{
return counter;
}
finally
{
rwLock.ExitReadLock();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment