Multiple Producer Consumer Project
We have studied the Producer/Consumer problem and implemented a solution using semaphores. It was assumed there was a single producer thread and a single consumer thread. The program that implements this solution is called prodcons1.c and appears in the computer codes directory on the course home page. By now you should have had a chance to compile and run the program using the script file comp1. In this project, we will write a Producer/Consumer program that spawns a user specified number of producer and consumer threads. The number of producer and consumer threads could be different. We will call the new program prodcons3.c. You will run it from the command line with three parameters. The first parameter will be the number of items to put into and take out of the buffer. The second will be the number of producers; the third will be the number of consumers. For example, the commandprodcons3 200 20 30would spawn 20 producers and 30 consumers that would insert and remove 200 items from the buffer.
How do I get started?There is a program called prodcons2.c that spawns a user specified number of producer threads. The program can be found in the computer codes directory. Study this program to see how it spawns multiple producers. Modify the program so it does the same for the consumers. Your program should produce output similar to prodcons2.c. At the end of the program, prodcons2.c prints out the number of items each thread inserted into the buffer. Prodcons3.c should print this out as well. In addition, it should print the number of items each consumer thread removed from the buffer. You should modify the script comp to compile and build the executable program prodcons3.
What do I hand in?
Please hand in a hard copy of the program with you name on the first line and output for 10 producers, 5 consumers and a buffer of size 500. Make sure that you leave your program in your home directory in a file called prodcons3.c
When is the project due?
The project is due Tuesday, November 12. Projects will not be accepted after the due date.