Exemple #1
0
        static void Main(string[] args)
        {
            BoundedBuffer buf = new BoundedBuffer(4);

            Producer prod = new Producer(buf, 100);

            Consumer con = new Consumer(buf);

            Parallel.Invoke(prod.run() , con.run());
        }
Exemple #2
0
 public Producer(BoundedBuffer boundedBuffer, int howMany)
 {
     if (boundedBuffer == null)
     {
         //ArgumentNullException	if buffer is null
         throw new ArgumentNullException();
     }
     if (howMany < 0)
     {
         //ArgumentOutOfRangeException	if howMany< 0
         throw new ArgumentOutOfRangeException();
     }
     this.BoundedBuffer = boundedBuffer;
     this.HowMany = howMany;
 }
Exemple #3
0
        public static void Main(string[] args)
        {
            BoundedBuffer bf = new BoundedBuffer(8);
            Producer producer = new Producer(bf,200);
            Consumer consumer = new Consumer(bf);
            Consumer consumer2 = new Consumer(bf);
            Thread pt = new Thread(producer.Run);
            Thread ct = new Thread(consumer.Run);
            Thread ct2 = new Thread(consumer2.Run);
            pt.Start();
            ct.Start();
            ct2.Start();




        }
Exemple #4
0
 public Consumer(BoundedBuffer boundedBuffer)
 {
     BoundedBuffer = boundedBuffer;
 }