Professional Documents
Culture Documents
Distributed Systems Dining Philosophers
Distributed Systems Dining Philosophers
Distributed Systems Dining Philosophers
Solution: To code this solution, we need to distinguish among three states in which
we may find a philosopher. For this purpose, we introduce the following data
structure:
EATING – When philosopher has got both the forks, i.e., he has entered
the section.
Philosopher i can set the variable state[i] = EATING only if her two
neighbors are not eating
(state[(i+4) % 5] != EATING) and (state[(i+1) % 5] != EATING).
filter_none
brightness_4
monitor DP
status state[5];
condition self[5];
Pickup(int i)
{
state[i] = hungry;
test(i);
self[i].wait;
}
Putdown(int i)
{
state[i] = thinking;
test((i + 1) % 5);
test((i + 4) % 5);
}
test(int i)
{
state[i] = eating;
self[i].signal();
}
}
init()
{
for
i = 0 to 4
state[i] = thinking;
}
} // end of monitor