CS 284 Operating Systems
Programming Assignment #7

Due: 2/26/2001 - Class Time

Write a C program that produces enough neatly formatted out to demonstrate that it has correctly performed the following:

  1. main() creates 5 producer threads and 2 consumer threads and then waits (joins) until they have all exited (thr exit).
  2. main() reports how many widgits each producer produced (reported back via a return value) and how many widgits each consumer consumed (reported back via a return value).
  3. The producers should produce a TOTAL of 50 widgits and then exit.
  4. The consumers should of course consume all 50 and then exit.
  5. A producer should produce an additional widgit every 1 - 5 random seconds (note: rand is NOT MT-Safe).
  6. A consumer should consume an additional widgit every .1 - .8 random seconds
  7. Producers place widgits INTO and consumers remove widgits FROM an area large enough to hold a maximum of 10 widgits (Buffer).

Program design issues:

  1. Consumers should cond_wait(...) if there are no widgits available to be consumed
  2. Producers should cond_wait(...) if the Buffer is full.
  3. Producers and consumers should cond_signal eachother to alert a waiting thread to wake up.
  4. No 'shared resource' should be accessed without the benefit of a mutex_lock().

Sample output results

=================================================================

You should use the 'script' command to capture all necessary information for handin.