public static void groupThreadWrite(ConcurrencyUtils.LightSwitch LS) { while (true) { LS.Acquire(); Console.WriteLine("Group thread #" + Thread.CurrentThread.Name); Thread.Sleep(3600); LS.Release(); } }
public static void lonelyThreadWrite(ConcurrencyUtils.Semaphore semaphore) { while (true) { semaphore.Acquire(); Console.WriteLine("I'm a lonely thread"); Thread.Sleep(100); semaphore.Release(); } }
public static void latchAcquire(ConcurrencyUtils.Latch latch) { Console.WriteLine(Thread.CurrentThread.Name + "trying to acquire"); latch.Acquire(); Console.WriteLine(Thread.CurrentThread.Name + "got through the latch"); }
public static void SemaphoreTest(ConcurrencyUtils.Semaphore testSemaphore) { while (true) { // Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Thread.CurrentThread.Name + ": Trying to Acquire..."); testSemaphore.Acquire(); // Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(Thread.CurrentThread.Name + ": acquired token!"); Thread.Sleep(DELAY_SECONDS * 1000); } }