public static int n = 2; //Defined value in the project guidelines static void Main(string[] args) { //Create the order buffer Semaphore read = new Semaphore(n, n); //Use a read and write semaphore to manage which threads can access buffer Semaphore write = new Semaphore(n, n); orderBuffer = new Buffer(read, write); //Create the airline object //Create the Airline thread and pass in the start function. (airlineFunc) Airline airline = new Airline(); Thread airlineThread = new Thread(new ThreadStart(airline.airlineFunc)); airlineThread.Name = "Airline 1"; airlineThread.Start(); //start one airline thread //Create the travelAgency Object //Define the travel agencies array. There will be 5 travel agency threads. TravelAgency travelAgency = new TravelAgency(); Thread[] agencies = new Thread[N]; //Define the Events used to trigger methods. Airline.priceCut += new priceCutEvent(travelAgency.ticketsOnSale); Airline.priceIncrease += new priceIncreaseEvent(travelAgency.ticketPriceIncrease); OrderProcessing.orderProcessed += new orderProcessedEvent(travelAgency.orderProcessed); OrderProcessing.orderFailed += new orderFailedEvent(travelAgency.orderFailed); TravelAgency.newOrderCreated += new orderCreatedEvent(airline.Order); //Start all the travel agency threads for (int i = 0; i < N; i++) { agencies[i] = new Thread(new ThreadStart(travelAgency.travelFunc)); agencies[i].Name = (i + 1).ToString(); agencies[i].Start(); } Thread.Sleep(2000); //allow all threads to start }
static void Main(string[] args) { Airline airline = new Airline(); travelAgnet TravelAgnets = new travelAgnet(); mcb = new MultiCellBuffer(3); Thread airlinefunc = new Thread(new ThreadStart(airline.airlineFunc)); airlinefunc.Start(); Airline.priceCut += new priceCutEvent(TravelAgnets.ticketOnSale); OrderProcessing.orderProcessed += new orderProcessedEvent(TravelAgnets.orderProcessed); travelAgnet.orderCreated += new orderCreateEvent(airline.runOrder); travelAgents = new Thread[5]; for (int i = 0; i < 5; i++) // N = 5 here { //Start N retailer threads travelAgents[i] = new Thread(new ThreadStart(TravelAgnets.travelAgentFunc)); //starts thread with retailer function travelAgents[i].Name = (i + 1).ToString(); travelAgents[i].Start(); } }