public void Result()
        {
            CountDownLatch cdl;

            cdl = new CountDownLatch(0);
            Assert.AreEqual(0, cdl.Count);

            cdl = new CountDownLatch(13);
            Assert.AreEqual(13, cdl.Count);

            cdl = new CountDownLatch(25);
            Assert.AreEqual(25, cdl.Count);
        }
        public void WaitingTask1()
        {
            var cdl = new CountDownLatch(1);
            var task = new Task(cdl);
            var runner = new Thread(task.DoSomething);

            runner.Start();
            Thread.Sleep(600);
            cdl.CountDown();
            runner.Join();

            Assert.IsTrue(task.Elapsed >= 500, "The task should cost more than 500 millis");
            Assert.IsTrue(task.Elapsed <= 700, "The task should cost less than 700 millis");
        }
        public void SimpleCountDown()
        {
            var cdl = new CountDownLatch(3);

            cdl.CountDown();
            Assert.AreEqual(2, cdl.Count);

            cdl.CountDown();
            Assert.AreEqual(1, cdl.Count);

            cdl.CountDown();
            Assert.AreEqual(0, cdl.Count);

            cdl.CountDown();
            Assert.AreEqual(0, cdl.Count);
        }
        public void WaitingTask2()
        {
            CountDownLatch cdl = new CountDownLatch(2);
            Task task = new Task(cdl);
            Thread runner = new Thread(task.DoSomething);

            runner.Start();
            Thread.Sleep(600);
            cdl.CountDown();
            Thread.Sleep(600);
            cdl.CountDown();
            runner.Join();

            Assert.IsTrue(task.Elapsed >= 1100,"The task should cost more than 1100 millis");
            Assert.IsTrue(task.Elapsed <= 1300, "The task should cost less than 1300 millis");
        }
 public void ZeroArgument()
 {
     var cdl = new CountDownLatch(0);
 }
 public Task(CountDownLatch cdl)
 {
     this.cdl = cdl;
 }
 public void MinorZeroException()
 {
     CountDownLatch cdl = new CountDownLatch(-1);
 }