Пример #1
0
        public void Await()
        {
            var wg = new WaitGroup();
            var i  = new byte[] { 0 };

            wg.Add(2);
            new Thread(new ParameterizedThreadStart((state) =>
            {
                Thread.Sleep(100);
                i[0] = (byte)(i[0] + 1);
                wg.Done();
            })).Start();
            new Thread(new ParameterizedThreadStart((state) =>
            {
                Thread.Sleep(100);
                i[0] = (byte)(i[0] + 1);
                wg.Done();
            })).Start();

            wg.Await();
            Assert.AreNotEqual(i[0], 0);
        }
        public void TestSecureRandomGenerator()
        {
            var results = new ConcurrentBag <byte[]>();
            var wg      = new WaitGroup();

            for (int i = 0; i < 10000; i++)
            {
                wg.Add(1);
                ThreadPool.QueueUserWorkItem(state =>
                {
                    results.Add(new SecureRandomGenerator().GenerateBytes(32));
                    wg.Done();
                });
            }
            wg.Await();
            Assert.NotEmpty(results);
            var flag = results.Select(x => new EqualableBinary(x))
                       .GroupBy(x => x)
                       .Any(x => x.Count() > 1);

            Assert.False(flag);
        }
Пример #3
0
        public void NoWaitOnZero()
        {
            var wg = new WaitGroup();

            wg.Await();
        }