Assignment
Objectives
- Learn thread programming.
- Practice concurrent programming with semaphores.
Using kernel threads and semaphores:
- Implement a correct solution to the producer-consumer (or bounded
buffer) problem with N producers and M consumers. Assume that there
is one bounded buffer and that producers and consumers randomly produce
to, or consume from, the buffer.
- You need to implement the following optional command line arguments
(use getopt, the man page can be found with "man 3 getopt" on the
linux boxes.)
- -p [number of producers]. Default is 2
- -c [number of consumers]. Default is 3.
- -s [number of items in buffer]. Default is 10.
- -n [number of iterations to run producer or consumer
thread]. Default is 5,000,000
- Since what you put in the bounded buffer is beside the point, you
may simply generate and put a sequence of integers in the buffer. You
will want to think carefully about sequence generation and buffer
insertion in light of testing your program's correctness.
- Graduate Students: Also
implement a correct solution to the readers-writers problem
with M readers and N writers where M and N are command line
parameters. Assume that readers have priority.
Each thread has the following structure:
for(i = 0; i < numberOfIterations; i++){
request-resource;
use-resource;
giveUpResource;
}
Please include a readme file, explaining
- How to run your code.
- Why your code implements a correct solution to the
problem
The assignment will be discussed in class and you are encouraged to flesh
out the specification.
Turning in your assignment
Turn in your tarred, gzipped file by
-
emailing it as an attachment to
cs446@cs.unr.edu
- Turning in hardcopy of your source and readme in class on the
due date.
Here is sample code:
- Getopt man page . Download and
view with "more" or "less"
- For the suns:
- For Linux:
Sushil Louis
Last modified: Mon Feb 23 12:27:48 PST 2004