Lab Assignment--Threads and Semaphores


Lab Code

To get the sample and exercise code, please use the following commands in your cs330 directory:
   wget www.labs.cs.uregina.ca/330/SemaphorePosix/Lab6.zip
   unzip Lab6.zip

(Please do this lab on os1 or os2)

Part 1

Read and complete Activity 2 from the following location http://www.csc.villanova.edu/~mdamian/threads/posixsem.html.

Part 2

Please modify the producer-consumer code that also came from this website. You will be writing code for the consumer function and adding code in main where the comments indicate to "Insert" code.

If you do not know how to start the consumer function, you might want to think about the answers to these questions:

Note: these questions do not need to be handed in.

A sample run is the following (yours might be slightly different):

[P0] Producing 0 ...
[P0] Producing 1 ...
[P0] Producing 2 ...
[P2] Producing 0 ...
[P1] Producing 0 ...
-----[C2] Consuming 0 ...
-----[C1] Consuming 1 ...
[P0] Producing 3 ...
[P2] Producing 1 ...
-----[C2] Consuming 2 ...
[P1] Producing 1 ...
-----[C1] Consuming 0 ...
-----[C0] Consuming 0 ...
-----[C2] Consuming 3 ...
-----[C1] Consuming 1 ...
[P2] Producing 2 ...
[P2] Producing 3 ...
-----[C1] Consuming 1 ...
-----[C0] Consuming 2 ...
-----[C0] Consuming 3 ...
[P1] Producing 2 ...
[P1] Producing 3 ...
-----[C2] Consuming 2 ...
-----[C0] Consuming 3 ...

Deliverables:

Submit 3 files to URCourses:

  1. goodcnt.c with the semaphore version of a mutex
  2. producer-consumer code with the 3 semaphores
  3. A script file showing: