public void TestCompleteAllMethod() { const int MAX_PROCESSORS = 8; var synchronizer = new Completion(); var waitingForAllThreadsToStart = new CountdownEvent(MAX_PROCESSORS); var waitingForAllThreadsToEnd = new CountdownEvent(MAX_PROCESSORS); for (var i = 0; i < MAX_PROCESSORS; i++) { var producer = new Thread(() => { waitingForAllThreadsToStart.Signal(); waitingForAllThreadsToStart.Wait(); synchronizer.WaitForCompletion(Timeout.Infinite); waitingForAllThreadsToEnd.Signal(); }); producer.Start(); } waitingForAllThreadsToStart.Wait(); synchronizer.CompleteAll(); waitingForAllThreadsToEnd.Wait(); waitingForAllThreadsToStart.Reset(); waitingForAllThreadsToEnd.Reset(); for (var i = 0; i < MAX_PROCESSORS; i++) { var producer = new Thread(() => { waitingForAllThreadsToStart.Signal(); waitingForAllThreadsToStart.Wait(); synchronizer.WaitForCompletion(Timeout.Infinite); waitingForAllThreadsToEnd.Signal(); }); producer.Start(); } waitingForAllThreadsToEnd.Wait(); }