5.65 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Solution to Dining Philosophers (cont.) void putdown (int i) { state[i] = THINKING; // test the left/right neighbors (who perhaps are waiting for your chopsticks) test((i + 1) % 5); test((i + 4) % 5); } Recall what test(i) does: // test(i) will set state of i to EATING only if: // (a) i is hungry and (b) the left & right neighbors are not eating void test (int i) { if ((state[i] == HUNGRY) && (state[(i + 1) % 5] != EATING) && (state[(i + 4) % 5] != EATING) ) { state[i] = EATING; self[i].signal(); //release i if it is waiting }
{}