turing:phils // ***************************************************************** // // * Mike Erlinger // // * CS 110 // // * Dining Philosophers // // * Project 2 // // * $Id: phil2.cc,v 1.1 1998/03/17 17:24:50 mike Exp mike $ // // * // // * // // * This program is an implementation of the Dining Philosophers // // * It starts with the solution from Tanenbaum's book. // // * There are either 4 input parameters or defaults are used: // // * Number of Phils - Default 5 // // * Eating Time - Default 6 sec // // * # of Eats - Default 4 // // * Thinking Time - Default 3 sec // // * // // * Semaphores: // // * Mutex, controls shared memory, initialized to 1. // // * Sems array of semaphores used to allow hungry phils to block // // * waiting for a fork, initialized to 1 // // * Done, controls when all processes done, initialized to number // // * of phils + 1. // // * // // * Shared Memory // // * An array of state variables for each phil. // // * Values are: Thinking, Hungry, Eating, Done. // // * Shared memory is acquired and attached in main. // // * // // * Operation // // * there is a main program which sets up all the semaphores // // * and shared data area. // // * It then forks off a number of phils, each phil is its own process. // // * main also forks off a waiter process, which prints out the status // // * of the table every 2 seconds. // // * main waits for all the phils and waiter to finish and then cleansup // // * and dies. // // * phils, think, then get hungry, then eat, then think, ... // // * eventually, they are done. // // * // ***************************************************************** Dining Philosophers program No command line arguments, then there are 5 philosophers, who eat for 4 sessions with 6 seconds a session who think for 3 secs and are hungry for 2 seconds otherwise: parameter 1 = Number Philosophers: parameter 2 = Eating Time: parameter 3 = Number of Eating Sessions: parameter 4 = Amount of Time Thinking: But the choice is no arguments or all the arguments. -------------------------------------- I AM THE WAITER #: P0 P1 P2 P3 P4 T H E L 1 T T T T T 5 0 0 0 2 T T T T T 5 0 0 0 3 H H H H H 0 5 0 0 4 H H E H E 0 3 2 0 5 H H E H E 0 3 2 0 6 H H E H E 0 3 2 0 7 T T T T T 5 0 0 0 8 H H H H H 0 5 0 0 9 H H E H E 0 3 2 0 10 H H E H E 0 3 2 0 11 H H E H E 0 3 2 0 12 T E T E T 3 0 2 0 13 T E T E T 3 0 2 0 14 H E H E H 0 3 2 0 15 E T E T H 2 1 2 0 16 E T E T H 2 1 2 0 17 E H E H H 0 3 2 0 .....