コード例 #1
0
        public void BasicTest_StartWaiters()
        {
            _count = 0;
            const int NumThreads = 10;
            CountDownLatch latch = new CountDownLatch(1);
            EventWaitHandle[] handles = new EventWaitHandle[NumThreads];

            for (int i=0; i<NumThreads; i++)
            {
                handles[i] = new EventWaitHandle(false, EventResetMode.ManualReset);

                Thread thr = new Thread(delegate(object x) { 
                    latch.Await();
                    Interlocked.Increment(ref _count);
                    ((EventWaitHandle)x).Set();
                });
                thr.Name = String.Format("Thread {0}",i);
                thr.Start(handles[i]);
            }
            EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
            Thread thr1 = new Thread(delegate(object x)
            {
                Thread.Sleep(100);
                EventWaitHandle.WaitAll(handles);
                ((EventWaitHandle)x).Set();
            });
            thr1.SetApartmentState(ApartmentState.MTA);
            thr1.Start(handle);
            
            Thread.Sleep(100);
            Expect(_count,EqualTo(0));
            latch.CountDown();
            handle.WaitOne();
            Expect(_count,EqualTo(NumThreads));
        }
コード例 #2
0
        public void AwaitThatTimesOutReturnsFalse()
        {
            const int NumThreads = 10;
            CountDownLatch latch = new CountDownLatch(NumThreads);

            bool result = latch.Await(50);
            Expect(result, False);
        }
コード例 #3
0
        public void AwaitThatDoesNotTimeOutReturnsTrue()
        {
            const int LatchCount = 10;
            CountDownLatch latch = new CountDownLatch(LatchCount);

            Thread thr = new Thread(delegate()
            {
                Thread.Sleep(100);
                for ( int i=0; i<LatchCount; i++ )
                    latch.CountDown();
            });
            thr.Start();

            bool result = latch.Await(50000);
            Expect(result);
        }
コード例 #4
0
        public void BasicTest_Countdown()
        {
            const int NumThreads = 10;
            CountDownLatch latch = new CountDownLatch(NumThreads);

            for (int i = 0; i < NumThreads; i++)
            {
                Thread thr = new Thread(delegate()
                {
                    Thread.Sleep(100);
                    latch.CountDown();
                });
                thr.Name = String.Format("Thread {0}", i);
                thr.Start();
            }

            latch.Await();
            Expect(latch.Count, EqualTo(0));
        }
コード例 #5
0
 /// <summary>
 /// Construct an info.
 /// </summary>
 /// <param name="status">Current status.</param>
 /// <param name="startPoint">Start point.</param>
 public Info(int status, long startPoint)
 {
     _status     = new AtomicInteger(status);
     _startPoint = startPoint;
     _latch      = new CountDownLatch(1);
 }
コード例 #6
0
 /// <summary>
 /// Construct an info.
 /// </summary>
 /// <param name="status">Current status.</param>
 /// <param name="startPoint">Start point.</param>
 public Info(int status, long startPoint)
 {
     _status = new AtomicInteger(status);
     _startPoint = startPoint;
     _latch = new CountDownLatch(1);
 }