The following pseudo-code is purported as a solution to the Dining Philosopher's
problem, which may lead to potential deadlock as all five philosophers are hungry
simultaneously and sitting at the table and all pick up the left chopstick and do not want
to release them.
/* program dining philosophers */
Semaphore chopstick [5] = {1, 1, 1, 1, 1}
The structure of Philosopher i:
do {
wait (chopstick[i]);
wait (chopstick[ (i + 1) % 5]);
eat...
signal (chopstick[i]);
signal (chopstick[ (i + 1) % 5]);
} while (True);
think...
You have to re-write the pseudo-code using the following idea: Allow at most four
philosophers to be sitting simultaneously at the table. For example, at most four
philosophers can be in the dining room at any time. (Hint: Use additional
semaphore.)