Example #1
0
        public static void Main(string[] args)
        {
            int result = 0;
            Cell cell = new Cell();

            Producer producer = new Producer(cell, 5);
            Consumer consumer = new Consumer(cell, 5);

            Thread producerThread = new Thread(new ThreadStart(producer.ThreadRun));
            Thread consumerThread = new Thread(new ThreadStart(consumer.ThreadRun));

            try
            {
                producerThread.Start();
                consumerThread.Start();

                producerThread.Join();
                consumerThread.Join();
            }
            catch (ThreadStateException e)
            {
                Debug.WriteLine(e);
                result = 1;
            }
            catch (ThreadInterruptedException e)
            {
                Debug.WriteLine(e);
                result = 1;
            }

            Environment.ExitCode = result;
        }
Example #2
0
        static void Main(string[] args)
        {
            BoundedBuffer buf = new BoundedBuffer(4);

            Producer prod = new Producer(buf, 10);
            Consumer con = new Consumer(buf, 10);

            Parallel.Invoke(prod.Run, con.Run);
        }
Example #3
0
        static void Main()
        {
            var buf = new BoundedBuffer(4);

            var prod = new Producer(buf, 10);
            var con = new Consumer(buf);

            Parallel.Invoke(prod.Run, con.Run);
        }
        public void TestMethod1()
        {
            BoundedBuffer buf = new BoundedBuffer(4);

            Producer prod = new Producer(buf, 10);
            Consumer con = new Consumer(buf, 10);

            Parallel.Invoke(prod.Run, con.Run);
        }
Example #5
0
        static void Main(string[] args)
        {
            BoundedBuffer buffer = new BoundedBuffer(1);

            Producer prod = new Producer(buffer, 400);
            Consumer cons = new Consumer(buffer);


            //Brug Parallel.Invoke til at køre dem
            Parallel.Invoke(prod.Run, cons.Run);

            Console.ReadLine();
        }
Example #6
0
        private static void BlockingCollectionBufferRun()
        {
            Logger.Info("Program started; 1 producer, 2 consumers");
            BlockingCollectionBuffer buffer = new BlockingCollectionBuffer(25);
            Producer producer = new Producer(buffer, 10);
            Consumer consumer = new Consumer(buffer);
            Consumer consumer2 = new Consumer(buffer);
            Task.Factory.StartNew(producer.Run);
            Task.Factory.StartNew(consumer.Run);
            Task.Factory.StartNew(consumer2.Run);

            //thread1.Start();
            //thread2.Start();
            //thread3.Start();
            //thread1.Join();
            //thread2.Join();
            //thread3.Join();
            Console.ReadLine();
            Logger.Info("Program ended");
        }
Example #7
0
        static void Main(string[] args)
        {
            BoundedBuffer buf = new BoundedBuffer(4);

            Producer prod = new Producer(buf, 10);
            Consumer con = new Consumer(buf);
            Consumer con2 = new Consumer(buf);


            Parallel.Invoke(prod.Run, con.Run, con2.Run);
           


            Console.WriteLine("The buffer was filled {0} times.", buf.NumberOfFills);
            Console.ReadKey();

            ////Parallel.Invoke(
            ////    () => Console.Write(""),
            ////    () => Console.Write("")
            ////    );
        }