var lEnter:sem = 1, lPot:sem = 1, lCall:sem = 1, lArrive:sem = 1; var iCounter: int; void *savage (void *arg) { int iSid = (int) arg; int iCounter2 = 1; P(lEnter); P(lPot); printf("\nPot: %d", iPot); if (iPot == 0) { V(lPot); P(lCall); iCall = 1;//call the cook! V(lCall); sleep(1); P(lCall); while (iCall == 1) { V(lCall); sleep(3); //sleep until cook refills P(lCall); } V(lCall); } else V(lPot); P(lArrive); iNumArrive--; V(lArrive); P(lPot); iPot--; V(lPot); V(lEnter); printf("\nSavage %d eats!", iSid); } void *cook (void *arg) { iCounter = 1; do { if (iCounter == 0) V(lArrive); P(lPot); P(lCall); if ((iPot == 0) && (iCall == 1)) { iPot = 2; iCall = 0; printf("\nCook refills!"); } V(lCall); V(lPot); iCounter = 0; P(lArrive); }while (iNumArrive > 0); V(lArrive); }