Due: Monday, 31 October
Project 3
References:
- Chapter 14 and section 15.4 in Understanding Unix/Linux Programming,
by Bruce Molay.
- pThreads
reference
- Another POSIX threads
tutorial
The Problem
Since Christmas (and Christmas break) is approaching, you are to coordinate Santa,
his reindeer, and his elves to prepare for the big Christmas eve trip. In
particular, you must solve the following problem in a program on the linux server
using the pthread library.
Santa Claus sleeps in his shop at the North Pole and can only be awakened by either
- all nine reindeer being back from their vacation in the South Pacific, or
- by
some of the elves having difficulties making toys.
To allow Santa to get some sleep,
the elves can only wake him when three of them have problems. When three elves are
having their problems solved, any other elves wishing to visit Santa must wait for
those elves to return. If Santa wakes up to find three elves waiting at his shopÕs
door, along with the last reindeer having come back from the tropics, Santa has
decided that the elves can wait until after Christmas, because it is more important
to get his sleigh ready. (It is assumed that the reindeer donÕt want to leave the
tropics, and therefore they stay there until the last possible moment.) The last
reindeer to arrive must get Santa while the others wait in a warming hut before being
harnessed to the sleigh.
Requirements
- Santa, each elve, and each reindeer must be a separate thread.
- You must have 20 elves and 7 reindeer.
- You must use the pthread library. You can use any synchronization
primitive allowed in the library, but you must synchronize the threads to
determine when to wake Santa and when all reindeer have arrived.
- Note that you are trying to synchronize three different types of threads.
- Reindeer should sleep a random amount of time before they return from the
tropics. This time, however, must be long enough so that Santa is awakened
at least 3 times by elves before the reindeer arrive.
- Elves must also work a random amount of time before they run into a problem.
Note that you have to time this so that enough elves will have problems before
the reindeer start arriving.
- Your output must be easy to read and very intuitive. If I can't figure
out what's going on, then there must be something wrong.
Documentation
- You must hand in a hard copy of all code in class on the due date.
- You must include a readme file that
explains your results and details how the various times relate to each other. If there are
any unexpected results (a time of 0 sec, for example) you must explain that also.
- Your program must be user friendly.
- Every file in your solution must contain a comment
giving your name and the assignment number. This comment must list every function
that is defined in the file and the purpose of each.
- There must also be a separate commnent before the main function. This
comment should briefly describe the purpose of the program, describe
how it is implemented, given the major interface elements, etc.
- Finally, each function (including the main function) must have a beginning
comment that includes the following components:
- The name of the function
- The function inputs and outputs
- Changes to any global variables or kernel data structures
- System calls made from the function
- Your program must also have appropriate comments. You do not have to comment each line
of the program, but you must comment each section, feature, and functional unit of the code.
- Your program must also be appropriately formatted with tabs, spaces, etc. You will be
penalized if your code is not easy to read.
Requirements.
- I will compile and run your solution on the linux server. I will use
gcc for the compiler.
- You must hand in a hard copy of all code that you use in
your solution.
Revision History
| Date |
Revision |
| 16 September |
Posted Project |