static void Main(string[] args) { // change Airline air = new Airline(); // create an airline to pass the airline function for threading // change // Instantiate 3 airline threads and then start them Thread airline1 = new Thread(new ThreadStart(() => air.priceModel("airline1"))); // start the thread with the passed-in parameter airline1 string Thread airline2 = new Thread(new ThreadStart(() => air.priceModel("airline2"))); // start the thread with the passed-in parameter airline2 string Thread airline3 = new Thread(new ThreadStart(() => air.priceModel("airline3"))); // start the thread with the passed-in parameter airline3 string airline1.Name = "airline 1"; airline2.Name = "airline 2"; airline3.Name = "airline 3"; airline1.Start(); airline2.Start(); airline3.Start(); // Instantiate a travel agency object in order to use its methods TravelAgency travel = new TravelAgency(); Airline.priceCut += new priceCutEvent(travel.ticketsOnSale); // have the travel agency method subscribe to airline event Thread[] travelAgencies = new Thread[5]; // create 5 travel agency threads for (int i = 0; i <= 4; i++) // N = 5 (for five travel agency threads) { // Start 5 travel agency threads travelAgencies[i] = new Thread(new ThreadStart(travel.travelAgencyFunc)); travelAgencies[i].Name = "travel agency " + (i+1).ToString(); travelAgencies[i].Start(); } // create buffer classes, etc. }
public static void Main() { // Initialize Airline and TravelAgency objects Airline airline0 = new Airline(); Airline airline1 = new Airline(); Airline airline2 = new Airline(); TravelAgency travelAgency = new TravelAgency(); // Initialize and start Threads Thread[] airlines = new Thread[3]; for (int i = 0; i < 3; i++) { airlines[i] = new Thread(new ThreadStart(airline0.AirlineFunc)); airlines[i].Name = "AIRLINE " + i; airlines[i].Start(); airlineThreadCount++; } Thread[] travelAgencies = new Thread[5]; for (int i = 100; i < 105; i++) { travelAgencies[i - 100] = new Thread(new ThreadStart(travelAgency.TravelAgencyFunc)); travelAgencies[i - 100].Name = "TRAVEL AGENCY " + i; travelAgencies[i - 100].Start(); } // Bind TravelAgency event handler to Airline event Airline.PriceCutEvent += new PriceCutDelegate(travelAgency.TicketPriceCut); // Wait for all threads to start and block on the semaphore Thread.Sleep(500); // Release 3 slots to start program orderBuffer.sem.Release(3); confirmationBuffer.sem.Release(3); Console.ReadLine(); }