예제 #1
0
파일: Program.cs 프로젝트: vonwenm/Jibu
        public override void Run()
        {
            try
            {
                // we use a Choice to listen 
                // on the Channel.
                Choice choice = new Choice(customers);

                switch (choice.TryFairSelect())
                {
                    case 0:
                        // We got a seat => sit down
                        customers.Write(this);
                        break;
                    case -1:
                        // no seats => leave shop
                        LeaveShop();
                        break;
                }

            }
            catch (PoisonException)
            {
                // if the channel has been
                // poisoned the shop must be closed
                Console.WriteLine(name + ": Too late! Shop is closed.");
            }
        }
예제 #2
0
파일: Dispatch.cs 프로젝트: vonwenm/Jibu
        public override void Run()
        {            
            // Here the desired number of taxi tasks are created and started.
            // Note that by using AsyncParallel the program can proceed
            // even though the taxi tasks are running. Had we used Parallel
            // the Run method would have blocked until Run returned.

            for (int i = 0; i < numTaxis; i++)
                new Taxi(taxiChan.ChannelReader, ackChannel.ChannelWriter).Start();

            // We create a choice that monitors two alternatived:
            // 1. A reader has read from the taxiChan - in this case meaning 
            // at least one vacant taxi
            // 2. A writer has written to the achChannel - meaning that
            // a taxi has picked up a customer.
            Choice choice = new Choice(taxiChan.ChannelWriter, ackChannel.ChannelReader);

            
            while (true)
            {
                // We make a fair selection over the two alternatives meaning 
                // that we cycle through the alternatives if they are ready. 
                switch(choice.FairSelect())
                {
                    case 0:
                        Tuple<int, int , string> t = customerChan.Read();
                        taxiChan.Write(t);
                        vacantTaxis--;
                        Console.WriteLine("Vacant taxis: " + vacantTaxis);
                        break;
                    case 1:
                        ackChannel.Read();
                        vacantTaxis++;
                        break;
                }
            }
        }
예제 #3
0
파일: Timer.cs 프로젝트: vonwenm/Jibu
 internal override AlternativeType Enable(Choice choice)
 {
     lock (lockObject)
     {
         if (!pending)
         {
             currentChoice = choice;
             return AlternativeType.False;
         }
         return AlternativeType.Timer;
     }
 }
예제 #4
0
 internal override AlternativeType Enable(Choice choice)
 {
     return(channel.Enable(choice));
 }
예제 #5
0
 internal abstract AlternativeType Enable(Choice choice);