Dining Philosophers Project

(updated 10/28/04 - use files dinigpsk.cpp and comp_dp to create and build program)

The Project

Write a program that solves the Dining Philosophers problem. The problem was described in class and in the Chapter 7 of the text. A detailed description of the problem appears in the text Modern Operating Systems, second edition, by A.S. Tanenbaum.

A semaphore solution is available on the course web site under the codes section. The file containing the solution is diningp. This project requires that you develop the pseudo code in diningp into a working multithreaded code where each thread represents one philosopher. Your code must satisfy the synchornization constraints of the problem; i.e., philosophers cannot share forks,the maxium number of philosophers should be in the eating state, and the philosophers should not deadlock.

In order to track the activities of the threads, your program will use a grahical display. When your program runs, it will display a ring of circles on the monitor - one circle for each philosopher. The color of the circle will indicate the state of the philosopher (red - THINKING, green - EATING, and yellow - HUNGRY). In order to watch the state transitions, your code will have to slow down the philosophers a bit. The functions that represent the eating and thinking states should have a delay of about 3 or 4 seconds (use the sleep() function).

The required graphics interface is done for you. The code you develop will call two graphics routines: init_phil_table to initialize the graphics screen, and display_phil to change the color of a philosopher. The program phil_main.cpp shows how to use these two routines. You will have to include the file phil_table.h in your code to access the graphics routines.

The code prodcons3.c, available on the web site, shows how to use the POSIX threads and semaphores required in this project.

Note: 10/28/04 Use the skeleton program diningpsk.cpp to create your program. It has all the needed header files and many essential functions. You should copy diningpsk.cpp to the file diningp.cpp. The script comp_dp will compile diningp.cpp and build the executable. The script comp_dp links the needed threads and grahpics libraries. You must copy phil_table.h to your local directory.

What do I hand in?

Please provide the following:

When is the project due?

The due date for the project is Tuesday, November 16.

Choice of Language

C++ is the preferred language for this project. If you want to use Java, please discuss it with me.