Exemplo n.º 1
0
        static void Main(string[] args)
        {
            _pool = new Semaphore(0, 2);
            MultiCellBuffer multiCellBuffer = new MultiCellBuffer();
            Airline         airline         = new Airline(multiCellBuffer);

            Thread airlineThread = new Thread(new ThreadStart(airline.airlineFunc));

            airlineThread.Start();         // Start one farmer thread

            TravelAgency travelAgency = new TravelAgency(multiCellBuffer);

            Airline.priceCut += new priceCutEvent(travelAgency.ticketsOnSale);

            Thread[] travelAgencies = new Thread[5];
            for (int i = 0; i < 5; i++)
            {   // Start N retailer threads
                travelAgencies[i]      = new Thread(new ThreadStart(travelAgency.travelAgencyFunc));
                travelAgencies[i].Name = (i + 1).ToString();
                travelAgencies[i].Start();
            }
            Thread.Sleep(500);
            _pool.Release(2); //Opening up semaphore
            Console.WriteLine("Main thread exits.");
        }
Exemplo n.º 2
0
 public Airline(MultiCellBuffer multiCellBuffer)
 {
     this.multiCellBuffer = multiCellBuffer;
 }
Exemplo n.º 3
0
 public TravelAgency(MultiCellBuffer multiCellBuffer)
 {
     this.multiCellBuffer = multiCellBuffer;
 }