/* choose.h %W% %G% Interface to routine to choose next smoker. Students are *not* not modify this file. Prepared for COP4610, Spring 1994 --Ted Baker Added more comments, 3 February 1994. */ #define N 4 /* the number of threads */ #define VENDOR 0 #define HAS_TOBACCO 1 #define HAS_PAPER 2 #define HAS_MATCHES 3 int exited[N]; /* exited[i] == 1 iff thread has exited */ extern int choose(); /* choose() Will return an arbitrary value i in the range 1..3, but which is guaranteed to satisfy exited[i] !=0, if such a value exists. Otherwise, it will return zero. 0 signifies all smokers have exited | 1 signifies the smoker that has tobacco has been chosen | 2 signifies the smoker that has paper has been chosen | 3 signifies the smoker that has matches has been chosen */ extern void smoker_wait_msg(int self); /* | should be called by each smoker just before it waits for ingredients. The self argument should identify the particular smoker. */ extern void smoker_done_msg(int self); /* should be called by each smoker when it is done smoking. | It should be called before the smoker signals the vendor to | wake up, or the order of messages may show one smoker | finishing after another smoker has started. The self argument should identify the particular smoker. */ extern void smoker_exit_msg(int self); /* should be called by each smoker when it is about to exit. It sets exited[self] = 1, as a side-effect. The choose() function relies upon this. This prevents the vendor from causing a deadlock by putting out ingredients that only can be used by an exited smoker. | It should be called before the smoker signals the vendor to | wake up, or the vendor may go ahead and put out ingredients | for the exited smoker, causing a deadlock. The self argument should identify the particular smoker. */ extern void vendor_service_msg(int choice); /* should be called by the vendor when it serves ingredients. | It should be called before the vendor signals the smoker to | wake up. The choice argument should identify the smoker who can use the ingredients. */ extern void vendor_exit_msg(); /* should be called by the vendor when it exits This should only happen after all the smokers have exited, to avoid a deadlock. */