CS 110, Architecture and Operating Systems
Dining Philosophers Project
Version 1.00
Due March 1, 2002, at 9 PM
30 Points for Basic Project
10 Points for Demo
Introduction
You are to implement a
robust solution to the
Dining Philosophers problem.
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.
- You cannot use busy waiting.
- You are to use your semaphore wrappers to provide necessary
semaphores.
- You are to use Solaris shared memory. See
below about
wrapping these calls in a class or wrapper.
- 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.
- Each philosopher must keep a count of the number of times he
has eaten.
- When each philosopher has eaten the maximum 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 Dining Philosophers is a neat problem, as written no one knows what the
heck is going on.
Thus you
MUST
have another process,
the waiter,
who monitors the philosophers' table.
Because he wants to get a good tip,
every 2 seconds the Waiter
looks at the table and determines what is going on.
He prints this data in a horizontal
``Santillo'' format:
- Printout #
- The current values in the state table for each philosopher,
e.g., hungry (H), thinking (T), eating (E), or done (D).
- How many philosophers are thinking.
- How many philosophers are hungry.
- How many philosophers are eating.
- How many philosophers remain at the table.
Termination
When all the philosophers are done eating
the Waiter prints out one more time and
the program dies.
Input Parameters
There are 4 parameters to the program (in order). If all
parameters are omitted, default values must be used.
- 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 4.
- How long (in seconds) each philosopher thinks. Defaults to 3.
These parameters are provided as command line parameters
and you will get ALL or NONE
but you must check for valid values (i.e., all values must be positive).
- You are to use your C or C++ wrapper/class to handle the
management of semaphores.
- You are to create a C or C++ wrapper/class to handle the
management of shared memory.
This wrapper/class should have at a minimum operations to
create,
attach,
detach,
and
destroy,
shared memory.
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 (although may find
it useful to do so).
Stuff You Need to Turn In or Submit:
What to Turn In:
Where to Turn In:
To the plastic bin outside Geoff's office. Be sure to use the bin
marked "homework," not the one marked "abstracts."
What to Submit:
Your full implementation, all the commented code of your
running implementation, and your Makefile (yes, this is more than the hard copy
that you turn in). We should be able to build and test your program
from what you submit.
References:
Notes:
If you decide to NOT implement shared memory with a dynamically sized
array, then use a maximum size of 10 philosophers, but expect to
lose 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
problem statement.
As usual, if your program was invoked incorrectly (wrong number of
arguments, invalid arguments, etc.) then it should produce a usage
message on cerr
and exit with nonzero status. The usage
message should also specify the defaults for all parameters.
Last modified February 24, 2002 by geoff@cs.hmc.edu