You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/TestApp/HybrydLock.cs

29 lines
571 B

using System.Threading;
namespace TestApp
{
public class HybrydLock
{
private AutoResetEvent _lock = new AutoResetEvent(false);
private volatile int _counter = 0;
public void Enter()
{
if (Interlocked.Increment(ref _counter) == 1)
{
return;
}
_lock.WaitOne();
}
public void Leave()
{
if (Interlocked.Decrement(ref _counter) == 0)
{
return;
}
_lock.Set();
}
}
}

Powered by TurnKey Linux.