

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


We will simulate a size-bounded queue (implemented as a doubly-linked list with a limit on maximum size) being shared by multiple producers and multiple consumers running simultaneously. Suppose we have m producers and n consumers (where m and n are supplied as command line arguments). The initial main process creates a queue data structure. Make this queue global so all threads can access it. Then the main process will create m producer threads and n consumer threads.
We will fix the number of items each producer produces (as a command line argument). Then we will keep track of how many items each consumer actually consumed. At the end of the program, we print out the total number of items produced versus the total number of items consumed. These two numbers should be the same unless the program has race conditions.
The items are a structure that contain an unique id (basically number the items 1, 2 , 3 ,... as they are entered in the queue) and also contains the index of the producer that created it.
A template program has been provided for you to use as a starting point. The program is in the directory ∼amit/cs453/lab/producers-consumers and the main file is called pc.c. The directory also contains a relevant Makefile that you should use.
First, you will need to create a monitor version of your doubly linked list to use in this project. An additional feature we will add to it is the ability to set the maximum size of the list in the constructor. You will be using the POSIX Pthreads mutexes and and Pthreads condition variables to implement the monitor version of your doubly linked list. Rele- vant man pages are pthread mutex init, pthread mutex lock, pthread mutex unlock, pthread cond init, pthread cond wait, pthread cond signal. Please create a separate version that is a monitor. For example, this could be on a separate branch of your subversion tree.
Then the producer/consumer threads will use the monitor version of the doubly linked list to run the simulation. To test your monitor version, we will have the producers randomly
insert new items at the front or back of the queue. Similarly the consumers randomly remove^2 items from the front or back of the queue.
You should also have a Makefile that compiles and links your program. The name of the executable must be pc, which should be produced by typing in make. Also include a README file that contains your name, date, assignment number and observations about the assignment.
Put all these files in a directory (say ∼/cs453/p6). Change directory to this directory and execute the following command (on onyx) to submit the assignment.
submit amit cs453 5
or
submit amit cs552 5
This command will pick up all files in the current directory (as well as any sub-directories recursively) and time-stamp them before transferring the combined files to the instructor’s account.