コード例 #1
0
        public void DoDemonstration()
        {
            // Two instances of the calculator are created.  One is named "Odd"
            // (it calculates the 1st, 3rd, 5th... values in the sequence) the
            // other is named "Even".  They message each other back and forth
            // with the latest two values and successively build the sequence.
            var limit = 1000;

            // Two channels for communication.  Naming convention is inbound.
            var oddChannel = new Channel<IntPair>();
            var evenChannel = new Channel<IntPair>();

            using (ThreadFiber oddFiber = new ThreadFiber(), evenFiber = new ThreadFiber())
            {
                oddFiber.Start();

                var oddCalculator = new FibonacciCalculator(oddFiber, "Odd", oddChannel, evenChannel, limit);

                evenFiber.Start();

                new FibonacciCalculator(evenFiber, "Even", evenChannel, oddChannel, limit);

                oddCalculator.Begin(new IntPair(0, 1));

                oddFiber.Join();
                evenFiber.Join();
            }
        }
コード例 #2
0
        public void DoDemonstration()
        {
            // Two instances of the calculator are created.  One is named "Odd"
            // (it calculates the 1st, 3rd, 5th... values in the sequence) the
            // other is named "Even".  They message each other back and forth
            // with the latest two values and successively build the sequence.
            var limit = 1000;

            // Two channels for communication.  Naming convention is inbound.
            var oddChannel  = new Channel <IntPair>();
            var evenChannel = new Channel <IntPair>();

            using (ThreadFiber oddFiber = new ThreadFiber(), evenFiber = new ThreadFiber())
            {
                oddFiber.Start();

                var oddCalculator = new FibonacciCalculator(oddFiber, "Odd", oddChannel, evenChannel, limit);

                evenFiber.Start();

                new FibonacciCalculator(evenFiber, "Even", evenChannel, oddChannel, limit);

                oddCalculator.Begin(new IntPair(0, 1));

                oddFiber.Join();
                evenFiber.Join();
            }
        }