//------------------------------------------------------------------------ // Filename: // bridge-main.h // PROGRAM DESCRIPTION // This program solves the bridge-crossing problem using Hoar // style monitor //------------------------------------------------------------------------ #include #include "ThreadClass.h" #include "bridge-Thrd.h" // -------------------------------------------------------------------- // The main program // -------------------------------------------------------------------- void main(int argc, char *argv[]) { Vehicle *OneVehicle[MAX_THREADS]; // vehicle classes int Threads; // # of vehicles int Max_Run, i; if (argc != 3) { cout << "Use " << argv[0] << " #-of-iterations #-of-vehicles" << endl; exit(0); } Max_Run = abs(atoi(argv[1])); Threads = abs(atoi(argv[2])); // validate user's input if (Threads > MAX_THREADS) { cout << "The no. of vehicles is too large. Reset to " << MAX_THREADS << endl; Threads = MAX_THREADS; } for (i = 0; i < Threads; i++) { OneVehicle[i] = new Vehicle(i+1, Max_Run); OneVehicle[i]->Begin(); } for (i = 0; i < Threads; i++) // wait for vehicles OneVehicle[i]->Join(); Exit(); }