Professional Documents
Culture Documents
The Dining Philosophers Problem in Java
The Dining Philosophers Problem in Java
Philosophers Problem in
Java
1. Introduction
The Dining Philosopher Problem states that K philosophers seated around
a circular table with one chopstick between each pair of philosophers.
There is one chopstick between each philosopher. A philosopher may eat
if he can pickup the two chopsticks adjacent to him. One chopstick may be
picked up by any one of its adjacent followers but not both.
2. The Problem
3. A Solution
An initial solution would be to make each of the philosophers follow the following
protocol:
As the above pseudo code describes, each philosopher is initially thinking. After a
certain amount of time, the philosopher gets hungry and wishes to eat.
At this point, he reaches for the forks on his either side and once he's got both
of them, proceeds to eat. Once the eating is done, the philosopher then puts the
forks down, so that they're available for his neighbor.