CS 110 Intro to Computer Systems
Dining Philosophers Project
Due 5 October, 9 PM
30 Points for Basic Project
10 Points for Demo
You are to implement a
Dining Philosopher's solution.
Your solution is to work in the following way:
You are free to use the book algorithm
(which was presented in class)
or any version of
the algorithm you might find.
use busy waiting.
You are to use your Semaphore wrappers to provide necessary
You are to use Solaris shared memory,
see below about wrapping these calls in a class
You are to collaborate in groups of two
Again, we will NOT assign partners.
Each of you
is to write your own code,
but use your partner to help debug and
test your solution.
This means that you MUST contact your partner first prior to
sending help requests to the graders or tutors or cs staff.
Indicate your partner in your code comments.
Add to each philosopher a count of the number of times
he has eaten.
When each philosopher has eaten the max number of times
(max provided as an input parameter)
the philosopher stops eating (his process dies).
The time period for each eating session is an
input parameter (fixed for all philosophers).
While this is a neat problem, as written no one knows what the
heck is going on.
have another process,
who monitors the Philosopher's table.
Because he wants to get a good tip,
every 2 seconds the Waiter
looks at the table and determines (prints out in a horizontal
The current values in the state table
for each Philosopher, e.g., Hungry (H), Thinking (T),
Eating (E), or Done (L).
How many Philosophers are thinking.
How many Philosophers are hungry.
How many Philosophers are eating.
How many Philosophers remain at the table.
When all the Philosophers are done eating
the Waiter prints out one more time and
the program dies.
There are 4 parameters to the program (in order):
These parameters are provided as command line parameters
and you will get ALL or NONE
but you must check for valid values.
How many Philosophers are coming to dinner,
defaults to 5.
How long (in seconds) each Philosopher
eats, defaults to 6.
How many times each Philosopher eats, defaults to
How long (in seconds) each Philosopher thinks,
defaults to 3.
You are to use your C++ wrapper/class to handle the management of semaphores.
You are to create a C++ wrapper/class to handle the management of shared memory.
This wrapper/class should have at a minimum operations to
You can view this wrapper/class as a reasonable interface to the unreasonable
interface provided by the operating system.
Note the word class is used here as an abstraction.
You do NOT have to create true C++ Classes.
Stuff You Need to Turn-in or Submit:
What to Turn-In:
A Commented, Partial Program Listing that Includes
An Intro program comment that describes your
overall implementation (1 to 2 pages):
including how long over all it took to write the algorithm;
to write the code; and to debug and to make work;
including the number of semaphores and
the use of each semaphore
your class templates for the semaphore and shared memory
classes. we really want your headings and your code.
I say class in a very abstract way; both of
these can be true C++ Classes, but they can also be implemented
via a set of wrapper functions. The key point is that
you are to choose a way to wrap the System Calls for
Semaphores and Shared Memory in a way that makes them
easy to use, e.g., something like
Up(semid) should up a semaphore.
a description of how you manage your processes,
e.g., something about how you manage your main program,
the Waiter, etc. Make sure to include comments about how
you terminate and determine termination of your processes.
Your comments need to be complete and detailed!!!
One or two Sample runs with the default input values.
There will be additional input values,
which will be used in demonstrating your program.
We do NOT want a copy of your full program listing!!!!!
What to Submit
Your full implementation, all the commented code of your
running implementation (yes, this is more than the hardcopy
that you turn-in).
Where to Turn-In:
To the plastic bin outside mike's office.
If you decide to NOT implement shared memory with a dynamic size
array, then use a max size of 10 philosophers, but expect to
loose 4 points. You MUST also indicate this choice in the
documentation comments at the front of your program.
We reserve the right to change the problem statement
when someone demonstrates the ambiguity of said
example, if the input was correct, the program should output at the
beginning, correct input, the parameters are set to the inputs, and show
that. If there is no input or wrong numbers of input, then your program
should output that fact and say that the defaults are used and show what the
defaults are. If the values of the input are not valid, then our program
should state that and say that the defaults are used, and show what the
Last modified October 3, 01 by email@example.com