public void Run()
        {
            ProduceConsumerQueue pcq = new ProduceConsumerQueue(5);

            Thread t1 = new Thread(() =>
            {
                for (int i = 0; i < 20; i++)
                {
                    pcq.Produce(i);
                }
            })
            {
                Name = "Producer"
            };

            Thread t2 = new Thread(() =>
            {
                for (int i = 0; i < 20; i++)
                {
                    Thread.Sleep(2000);
                    var val = pcq.Consume();
                }
            })
            {
                Name = "Consumer"
            };

            t2.Start();
            t1.Start();
            t2.Join();
            t1.Join();
        }
Exemple #2
0
 public ThreadPool(int threads)
 {
     _threads = threads;
     pcq      = new ProduceConsumerQueue(threads * 5);
 }