public void Test_OddEvenWithMutex() { OddEvenWorker worker = new OddEvenWorker(); Thread oddThread = new Thread(() => { worker.PrintOddValuesMutex(20); }); Thread evenThread = new Thread(() => { worker.PrintEvenValuesMutex(20); }); oddThread.Name = "OddTh"; evenThread.Name = "EvenTh"; Mutex myMutex = new Mutex(true, "OddEven"); oddThread.Start(); evenThread.Start(); // don't let them start until we release the mutex myMutex.ReleaseMutex(); oddThread.Join(); evenThread.Join(); Assert.IsTrue(true); }
public void Test_OddEvenWithSemaphore() { OddEvenWorker worker = new OddEvenWorker(); Thread oddThread = new Thread(() => { worker.PrintOddValuesSemaphore(20); }); Thread evenThread = new Thread(() => { worker.PrintEvenValuesSemaphore(20); }); oddThread.Name = "OddTh"; evenThread.Name = "EvenTh"; Semaphore semaphore = new Semaphore(1, 4, "MySemaphore"); semaphore.WaitOne(); oddThread.Start(); evenThread.Start(); // don't let them go until semaphore released semaphore.Release(); oddThread.Join(); evenThread.Join(); Assert.IsTrue(true); }
public void Test_OddEven() { OddEvenWorker worker = new OddEvenWorker(); Thread oddThread = new Thread(() => { worker.PrintOddValues(20); }); Thread evenThread = new Thread(() => { worker.PrintEvenValues(20); }); oddThread.Name = "OddTh"; evenThread.Name = "EvenTh"; oddThread.Start(); evenThread.Start(); oddThread.Join(); evenThread.Join(); Assert.IsTrue(true); }
public void Test_OddEven() { OddEvenWorker worker = new OddEvenWorker(); Thread oddThread = new Thread(() => { worker.PrintOddValues(20); }); Thread evenThread = new Thread(() => { worker.PrintEvenValues(20); }); oddThread.Name = "OddTh"; evenThread.Name = "EvenTh"; oddThread.Start(); evenThread.Start(); oddThread.Join(); evenThread.Join(); Assert.IsTrue(true); }
public void Test_OddEvenWithMutex() { OddEvenWorker worker = new OddEvenWorker(); Thread oddThread = new Thread(() => { worker.PrintOddValuesMutex(20); }); Thread evenThread = new Thread(() => { worker.PrintEvenValuesMutex(20); }); oddThread.Name = "OddTh"; evenThread.Name = "EvenTh"; Mutex myMutex = new Mutex(true, "OddEven"); oddThread.Start(); evenThread.Start(); // don't let them start until we release the mutex myMutex.ReleaseMutex(); oddThread.Join(); evenThread.Join(); Assert.IsTrue(true); }
public void Test_OddEvenWithSemaphore() { OddEvenWorker worker = new OddEvenWorker(); Thread oddThread = new Thread(() => { worker.PrintOddValuesSemaphore(20); }); Thread evenThread = new Thread(() => { worker.PrintEvenValuesSemaphore(20); }); oddThread.Name = "OddTh"; evenThread.Name = "EvenTh"; Semaphore semaphore = new Semaphore(1, 4, "MySemaphore"); semaphore.WaitOne(); oddThread.Start(); evenThread.Start(); // don't let them go until semaphore released semaphore.Release(); oddThread.Join(); evenThread.Join(); Assert.IsTrue(true); }