George Mason University
CS571 - Spring 2001
DEFAULT PROJECT ASSIGNMENT #1
Professor: Dr. Tan N. Nguyen
Email: tnguy1@cs.gmu.edu
The purpose of this project is to give you some practical experience
in the use of synchronization primitive.
ADVANCE PREPARATION:
You should complete the following steps before working on this project:
-
Step 1: Study the Java code on the Producer-Consumer problem
for chapters 5 and 7
-
Step 2: Develop a plan to use a computer language, e.g., Java, C, C++,
etc. to implement the following problem
-
Step 3: Implement the following problem.
PROBLEM:
Create two threads (that is NOT thread-safe), producer (P) and consumer
(C). P produces items and inserts them into a bounded buffer; C retrieves
items from the buffer and outputs them. Each item must be retrieved exactly
once, and all items are to be retrieved in the same order in which they
were inserted. Set up a timer mechanism to report elapsed and CPU
time consumed by the P/C during the experiment.
The producer is to generate the sequence of items 1, 2, ... , 100, and
insert them into the buffer by this schedule:
5:delay(15):10:delay(15):15:delay(15):20:delay(15):50
Where the numbers indicate how many items are inserted into the buffer
and the delays are in seconds.
The consumer is to consume items according to the following schedule:
delay(15):5:delay(15):20:delay(15):15:delay(15):60
The producer completes when all 100 items have been inserted into the
buffer. The consumer completes when it has made 100 retrievals and printed
them. The Producer-Consumer (PC) system completes when both P and C complete.
-
Program a circular buffer of capacity 5 elements between producer and consumer.
Use no semaphores or message queue or other synchronization solution. Use
only shared memory. Run the PC to completion 5 times. For each run, record
the output of the consumer and the total real time and CPU time.
If there are differences between the runs, please account for the differences.
Summarize your findings and draw conclusions.
-
Repeat the previous process with your own solution that must be thread-safe.
Do not use semaphore to synchronize P and C.
-
What did you learn from the experiment?