public void Go() { latch.Release(); sync.Acquire(); gone = true; sync.Release(); }
public static void TestOne() { Console.WriteLine("Threads will soon be started"); for (int i = 0; i < 10; ++i) { new Thread(OtherThread).Start(); } Console.WriteLine("Press any key to release the latch!"); Console.ReadLine(); latchOne.Release(); // Shows that it does not block once the latch has been released new Thread(OtherThread).Start(); }
public static void Main() { Thread[] threads = new Thread[15]; for (int i = 0; i < threads.Length; i++) { threads[i] = new Thread(TestLatchAcquire); threads[i].Name = "Test thread " + i; threads[i].IsBackground = false; threads[i].Start(); } Thread.Sleep(2000); Console.WriteLine("Latch acquire has not completed yet because there are no available tokens!"); Console.WriteLine("Let's see what happens when we release a token into the latch!\n"); Thread.Sleep(2000); _testLatch.Release(); }
/// <summary> /// Creates five threads waiting on the latch to be released, /// waits a specified amount of time and then releases the latch /// </summary> /// <param name="secondsToWait">The amount of time before releasing the latch in seconds</param> /// <returns>True if the test passed, false if the test failed</returns> private bool Test1(int secondsToWait = 2) { _latch = new Latch(); var threadPool = new List <Thread>(); for (var i = 0; i < 5; i++) { threadPool.Add(new Thread(WaitForLatch) { Name = "Thread " + (i + 1) }); } foreach (var thread in threadPool) { thread.Start(); } Thread.Sleep(secondsToWait * 1000); _latch.Release(); return(true); }
public void WaitForStartedBeforeStopping() { MyService serviceable = new MyService(sync1, sync2); ISync starting = new Latch(); ISync started = new Latch(); BlockWhileStartingExecutor executor = new BlockWhileStartingExecutor(starting, started); MyServiceSupport support = new MyServiceSupport(executor, serviceable); executor.ServiceSupport = support; Thread startThread = new Thread(new ThreadStart(executor.Start)); startThread.Name = "start"; startThread.Start(); Log("start thread started"); Latch stopping = new Latch(); Latch stopped = new Latch(); StoppingHelper helper = new StoppingHelper(support, stopping, stopped); Thread stopThread = new Thread(new ThreadStart(helper.Stop)); stopThread.Name = "stop"; stopThread.Start(); Log("stop thread started: waiting for stopping ..."); stopping.Acquire(); Log("stopping in progress ..."); Assert.IsFalse(executor.wasStarted); Assert.IsFalse(helper.wasStopped, "helper could stop before expected"); Log("allow to start ..."); starting.Release(); Log("waiting for started ..."); started.Acquire(); Assert.IsTrue(executor.wasStarted); stopped.Acquire(); Log("waiting for stop ..."); Assert.IsTrue(helper.wasStopped); Log("stopped ..."); }
protected void trigger_Triggered(object sender, EventArgs e) { triggeredLatch.Release(); }
public void Release() { latch.Release(); }
private void dispatcher_DeployEvent(object sender, DeployEventArgs args) { log.Debug("releasing latch"); eventLatch.Release(); log.Debug("latch released"); }
public void _Completed(OperationStatus anOperationStatus) { _status = anOperationStatus; _completed.Release(); }