Lab 6 (5 points)
CS550, Operating Systems
More on Parallel Programming
Name:
_____________________________________________
To submit this assignment, you may copy and paste the assignment
into a text editor such as nano, vi, notepad, MS Word, OpenOffice
Writer, etc. Zip the code and scripts showing the output of
your solutions, and submit the zip file to the dropbox for lab
6. The purpose of this lesson is to learn to about the
threaded solution to the Producer Consumer problem in the C
programming language.
Part 1
Unzip the threaded Producer-Consumer example from the examples page
on LittleFe. The command to do so follows below:
unzip prodcons.zip
If you are using a BCCD virtual machine, you will need to download
zip and unzip with the following command:
sudo apt-get install zip unzip
Then run:
unzip prodcons.zip
First we will learn about makefiles. All the unzipped files
should be in a directory called prodcons. There is a makefile
included within the zip file. It is called makefile.pc. Browse
the file using nano or another text editor. Compile all the
files in the zip file using the following command:
make
-f makefile.pc
Run the Producer-Consumer project with the following command:
./pc
Part 2
Modify the producer consumer project to use two producers and two
consumers.
Run the following command before compiling your code:
make
-f makefile.pc clean
This will remove the old object files from your directory.
Compile your code and run it again to ensure it works.
Save this code to submit it later.
Repeat the process above for two consumers and three producers.
What happens when you use two consumers and three producers? Why did this happen?
How would you modify the code to ensure it worked for any number of producers and consumers?
Part 3
Ensure that your code will
work for any number of producers and any number of consumers.
Assume that there will be at least one producer and at least one
consumer.
You should read in the number of producers and the number of
consumers from the keyboard. Ensure that your producers and
consumers are identified by their thread id within your output.