(Last revision 11/12/2002)
CS 3750 SECOND C++ Concurrent Programming Assignment (prog #2)
Errors in concurrent programs tend to be intermittant. They tend to be
manifested only under certain timings of events. The random delays in the
program will tend to make the timing of events change considerably each
time the program is executed. If you run the program several times and
check the output you are more likely to find out about possible errors than
if you just run the program one time and check the output.
- This assignment is much like the previous one. The difference is that
now, in the spaces between two trivets, there are TWO diners (sitting
opposite each other) instead of just one. The layout is like this:
(NORTH) Server T T T Busser (SOUTH)
(The T's in the diagram are trivets.)
- Make a copy of the foodPass2.cpp program. Read the program header
comments in order to figure out what the requirements of a solution
- Insert declarations and instructions into a copy of the program so
that it properly performs the required job.
You may use (only) ordinary variables and queuing semaphores as
implemented by sem.cpp and sem.h to achieve the synchronization of
For this assignment, you may work in teams of two (2) people. If you work
in a team, make sure that both names are in your comments!
More Discussion of the Assignment
When you think about doing this assignment, imagine that all the threads
(the server, busser, and all the diners) will run on a separate CPU of a
tightly-coupled multiprocessor. Of course, our Sun Ultra computing systems
are not tightly-coupled multiprocessors. Nevertheless, the point of this
exercise is for you to write a program that will work on *any* computing
system on which multiple processes can execute concurrently while sharing
A tightly-coupled multiprocessing system can be diagrammed this
CPU CPU CPU CPU CPU CPU CPU MEMORY
| | | | | | | |
| | | | | | | | |
CPU CPU CPU CPU CPU CPU CPU CPU CPU
Here we have a RAM memory being shared over a common bus by several CPU's.
It is possible that the different CPU's have radically different speeds.
Speed can be affected by the inherent power of the CPU, or by the current
load on the CPU. Besides that, it is impossible to tell which CPU will be
assigned to which thread. And also, each time we run the program, the
assignment can be different.
In your program, the mother process creates child threads to be the diners
and the food server. Then the mother thread plays the role of the busser.
The mother does nothing to direct the server and diners after she creates
In general it is a bad idea to create "traffic cop" threads, because the
traffic cop too often becomes a bottleneck. When every action has to be
approved by a master, events can only happen as fast as the master can
approve them. This would defeat the purpose of parallel processing.
The general rules for submitting assignments by e-mail are:
- Always send me e-mail as plain text in the main message
body. Never send me attachments.
- When you send a program source file, you also send
of your tests. Combine the source file and the script
shell archive (shar) file.
- I will tell you what subject line to use with each
message, and I need you to use exactly the
subject lines I give you. (I get hundreds of e-mail
messages at a time and your subject line allows me to
- Send each submission before midnight on the due date.
Here is what you have to turn in:
Note that there are no spaces in the subject lines given above. It is
important that you do not insert any spaces. My e-mail address is:
- By the first due date e-mail me a pseudo-code copy of your solution to
the problem -- a copy of foodPass2.cpp with the appropriate
Use this subject line: CS3750,prog2,pseudo
- By the second due date e-mail me a
Use this subject line: CS3750,prog2,final
- a completed copy of the foodPass2.cpp source file,
(Do not send me copies of sem.h or sem.cpp. I will compile your
copy of foodPass2.cpp on a Sun Ultra with my own copies of sem.h
and sem.cpp. To do the compile, I will use a "make" file just
like the one I am giving you. Your program should work for me
if it worked for you.)
- script(s) showing several successful test runs
For due dates, see
the class schedule.