3.4 Time to Make the Donuts
In C using UNIX system calls, demonstrate a producer-consumer network. The produce makes donuts and the consumers eat them by the dozens. Yum!
Your program will receive the following command-line arguments: PM (a production mode), DC (donut type count), CC (a consumer count), DDC (a donut dozen count), and QS (a queue size).
Your program will create a shared memory segment (man shm_overview), spawn one producer process, then spawn CC consumer processes. The shared memory segment should contain DC queues of size QS, one for each of the donut types. The queue should have semaphores (man semget) for locking and a ring buffer array for storing the values. Your program should kill the producer when all the consumer processes exit.
Your producer process should endlessly produce donuts. If PM is in-order, it should produce one donut of each of the DC types in sequence. If PM is rand, it should randomly determine which type of donut to produce. In this context, to produce donut #n of type ty means to put the integer n into the queue for type ty.
Your consumer processes should consume DDC dozen donuts. To consume a donut of type ty means to read the integer at the next slot in the queue for type ty. When consumer i finishes consuming dozen j, the consumer should display a line formatted as (yum i j ([ty di] ...)) where ty is the donut type and di is the donut identifier. Your consumers should consume donuts in an order determined by PM in the same way as producer (i.e. ordered or randomized).
Your program should have no other output than mentioned above.
You must use your program in a test and an experiment.
For the test, discover a set of command-line arguments to the program that produces deterministic output. Your README should include this output, clearly labeled.
For the experiment, run your program with rand 4 5 10 50 as arguments. Your README should include this output, clearly labeled. After this, produce a graph showing the probability of deadlock versus varying QS arguments. The graph should be ASCII art and based on a few different runs for each QS. Next, using the QS argument that produces 50% deadlocks, vary the CC argument from 1 to 10 and graph the results. Your README does not need the output for these experiments, only the graphs.
Your repository must contain the following files:
A README file that contains a short write-up of your project. It should discuss the approach you took to solving the problem, it should discuss any problems or issues that still remain, it should discuss any interesting things that you learned in the course of the project. Finally, it should provide the grade you believe the project deserves with a detailed explanation of why. This explanation should almost certainly focus on why you believe the program is correct.
Your README must contain the results of your experiment and your test.
This file must be in plain-text. If you need formatting, use Markdown. It must be limited to 80 characters wide, unless you are quoting program output.
Your source code, named a3.c.
A Makefile builds the program and runs the test.
This assignment will be graded based on its correctness and your ability to articulate why it is correct.