public class LockStatement
static SemaphoreSlim _sem = new SemaphoreSlim (3);
public static void Main()
for (int i = 1; i <= 5; i++) new Thread (Enter).Start (i);
static void Enter (object id)
Console.WriteLine (id_ + " wants to enter");
Console.WriteLine (id_ + " is in!");
Thread.Sleep(1000 * id_);
Console.WriteLine (id_ + " is leaving");