예제 #1
0
 private static async void Producer(Coordinator coordinator)
 {
     for (int i = 0; i < 10; i++)
     {
         Console.WriteLine("Enqueuing {0}", i);
         values.Enqueue(i);
         if (values.Count == 3)
         {
             Console.WriteLine("Queue full; switching to consumer");
             await coordinator.YieldTo(Consumer);
         }
     }
     // Dequeue any remaining items
     await coordinator.YieldTo(Consumer);
 }
예제 #2
0
 private static async void Producer(Coordinator coordinator)
 {
     for (int i = 0; i < 10; i++)
     {
         Console.WriteLine("Enqueuing {0}", i);
         values.Enqueue(i);
         if (values.Count == 3)
         {
             Console.WriteLine("Queue full; switching to consumer");
             await coordinator.YieldTo(Consumer);
         }
     }
     // Dequeue any remaining items
     await coordinator.YieldTo(Consumer);
 }
예제 #3
0
 private static async void Consumer(Coordinator coordinator)
 {
     int loopCount = 0;
     while (true)
     {
         Console.WriteLine("    Entering consumer loop; count {0}", loopCount);
         loopCount++;
         while (values.Count != 0)
         {
             Console.WriteLine("    Dequeued {0}", values.Dequeue());
         }
         Console.WriteLine("    Queue empty; switching to producer");
         await coordinator.YieldTo(Producer);
     }
 }
예제 #4
0
        private static async void Consumer(Coordinator coordinator)
        {
            int loopCount = 0;

            while (true)
            {
                Console.WriteLine("    Entering consumer loop; count {0}", loopCount);
                loopCount++;
                while (values.Count != 0)
                {
                    Console.WriteLine("    Dequeued {0}", values.Dequeue());
                }
                Console.WriteLine("    Queue empty; switching to producer");
                await coordinator.YieldTo(Producer);
            }
        }