Wednesday, June 17, 2009

Barrier multithreading primitive in C#






public class Barrier
{
public Barrier(int count)
{
Count = count;
}

public int Count{get; set;}

public void Wait()
{
lock(this)
{
if (--Count > 0)
{
System.Threading.Monitor.Wait(this);
}
else
{
System.Threading.Monitor.PulseAll(this);
}
}
}
}


No comments: