[an error occurred while processing this directive]

Lab 4

CS 5631, Spring 2004
Due Tuesday, March 30 (20 points)

Introduction

For Lab 4, implement a simulation of the dining philosophers problem. This will involve modifying a class for semaphores and a class for philosophers. When you have completed the modifications, philosophers will be able to compete for shared chopsticks, synchronized so that they do not get into a deadlock.

Setting up

Everything that you will need for this exercise is contained in a file named lab4.jar. You can copy the lab4.jar file from ~gshute/public/cs5631/lab4.jar to the directory where you want to do your work. Then give the following command.

    jar xf lab4.jar

This will create a new subdirectory named lab4. Change directory into that directory and look at a listing of the files. You should see the following files.

The main program can be found in PhilosopherMain.java. You will not need to modify this file, except possibly to change the kind of log reports that are made. Other than that, the only changes that you need to make are in the files Semaphore.java and Philosopher.java. The places where you need to add code are indicated by // FIXME comments. These comments sketch the algorithm that is used for synchronization. I recommend a careful reading of these files before you start adding code. You should try to get a good picture of the variables and methods that are available.

Implementation Notes

You should first implement the up() and down() methods in Semaphore.java using the Java wait() and notifyAll() methods. Then start working on the Philosopher.java file.

For this lab, I have modified the Log class so that all log entries are reported immediately. This is done so that you will see log reports even if your code results in a deadlock. The change to the class will be automatic if your class path has an entry for my class libraries (you set this up in the first lab). If you downloaded my libraries for work on your own computer, you should repeat the download.

If time permits, I may come up with a a deadlock detection scheme that allows the program to generate log reports even if there is a deadlock. If I can do this, I will send you email about it.

What to turn in

Turn in copies of the following:

[an error occurred while processing this directive]