137
The Dining Philosophers Problem
n
Each philosopher is a
process
n
One semaphore per
fork:
u
fork: array[0..4] of
semaphores
u
Initialization:
fork[i].count:=1 for
i:=0..4
n
A first attempt:
n
Deadlock if each
philosopher start by
picking his left fork!
Process Pi:
repeat
think;
wait(fork[i]);
wait(fork[i+1 mod 5]);
eat;
signal(fork[1+1 mod 5]);
signal(fork[i]);
forever