コード例 #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;
        }
コード例 #2
0
 public Producer(Cell box, int request)
 {
     _cell = box;
     _quantity = request;
 }
コード例 #3
0
 public Consumer(Cell box, int request)
 {
     _cell = box;
     _quantity = request;
 }