Class ReadWriteLock
{
private int Read;
private int Write;
private static Object _S= new Object();
public void ReadWriteLock()
{
Write=0;
Read=0;
}
public void GetReadLock()
{
while(Write);
Interlocked.Increment(ref Read);
}
public void ReleaseReadLock()
{
Interlocked.Decrement(ref Read);
}
public void GetWriteLock()
{
while(Read);
if(Read==0)
{
lock(_S)
{
if(Read==0)
{
Interlocked.Increment(ref Write);
}
}
}
}
}
public void ReleaseWriteLock()
{
Interlocked.Decrement(ref Write);
}