Homework 4: Dining Philosophers

Click here for an outline of a solution to the dining philosophers problem using a pseudo monitor.
This homework will require implementing this solution using a Java's wait() and notify() methods.

Begin by creating five philosophers, each identified by a number 0 ... 4.
Each philospher runs in a separate thread. Philosphers will
alternate between thinking and eating.

When a philosopher
wishes to eat, it invokes the method takeForks(philNumber),
where philNumber identifies the number of the
philosopher wishing to eat. When a philosopher finishes
eating, it invokes returnForks(philNumber).

Your solution will implement the following interface:

    public interface DiningCoordinator
    {

        // called by a philosopher when it wants to eat
        public void TakeForks(int philNumber);

        // called by a philosopher when it is finished eating
        public void returnForks(int philNumber);
    }

The implementation of the interface follows the outline of
the solution referred to above. Implement using the keyword synchronized,
along with wait(), notify(), and notifyAll().
To get more interesting behavior, use a helper class so your philosophers can take naps.

Big questions:
shold you use notify() or notifyAll()?
Should you test conditions using while-statements or if-statements?

Due: Sunday, Mar. 1


John Casey
Last modified: Wed Feb 18 16:15:19 EST 2009