138
The Dining Philosophers Problem
n
A solution: admit only 4
philosophers at a time
that tries to eat
n
Then 1 philosopher can
always eat when the other
3 are holding 1 fork
n
Hence, we can use
another semaphore T that
would limit at 4 the numb.
of philosophers “sitting at
the table”
n
Initialize: T.count:=4
Process Pi:
repeat
think;
wait(T);
wait(fork[i]);
wait(fork[i+1 mod 5]);
eat;
signal(fork[1+1 mod 5]);
signal(fork[i]);
signal(T);
forever