[an error occurred while processing this directive]
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.
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
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
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
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
You should try to get a good picture of the variables and methods that are
You should first implement the
methods in Semaphore.java using the Java
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.
Turn in copies of the following: