Ejemplo n.º 1
0
        private static void Populate(int n)
        {
            var mutex = new CountDownLatch(n);
            for (int i = 1; i <= mutex.Count; i++)
            {
                ThreadPool.QueueUserWorkItem((state) =>
                {
                    Console.WriteLine(state);
                    mutex.CountDown();
                }, i);
            }

            mutex.Await();
        }
Ejemplo n.º 2
0
        public void Test()
        {
            ConcurrentStack<int> stack = new ConcurrentStack<int>();
            stack.ForEach(i => Console.WriteLine(i));
            Console.WriteLine("---------------");
            CountDownLatch mutex = new CountDownLatch(20);
            for (int i = 1; i <= mutex.Count; i++)
            {
                ThreadPool.QueueUserWorkItem((state) =>
                {
                    stack.Push((int)state);
                    mutex.CountDown();
                }, i);
            }

            mutex.Await();
            stack.ForEach(i => Console.WriteLine(i));
           
        }