/* choose.c @(#)choose.c 1.1 19 Feb 1994 Routines to choose next smoker, and print out messages. The solution to the smokers problem should not depend on the body of the "choose" operation. In grading, various other versions of the "choose" operation may be used, that cause different execution orders. Prepared for COP4610, Spring 1994 --Ted Baker */ #include #include #include /* for exit() */ #include "choose.h" int count = 0; char *name[4] = {"VENDOR","HAS_TOBACCO","HAS_PAPER","HAS_MATCHES"}; int choose() { int choice; while (!(exited[1] && exited[2] && exited[3])) { choice = (count++%3)+1; if (!exited[choice]) return (choice); } return 0; } void smoker_wait_msg(int self) { printf("smoker %d (%s) waiting for ingredients\n",self,name[self]); } void smoker_done_msg(int self) { printf("smoker %d (%s) done smoking\n",self,name[self]); } void smoker_exit_msg(int self) { printf("smoker %d (%s) exiting\n",self,name[self]); exited[self] = 1; } void vendor_service_msg(int choice) { printf("vendor serves smoker %d (%s)\n",choice,name[choice]); } void vendor_exit_msg() { printf("vendor exiting\n"); exited[0] = 1; }