This assignment makes use of the files contained in this zip file. You are to write a program that creates three buffers, three producer threads, and three consumer threads. Each producer thread will be in an endless loop where it randomly chooses one of the three buffers, puts an "item" into the buffer, and then displays the contents of the buffer in the console window. Each consumer thread will be in an endless loop where it randomly chooses one of the three buffers, takes an "item" from the buffer, and then displays the contents of the buffer in the console window. The following file outlines a producer-consumer program that creates the producer and consumer threads and the three buffers. In the file are directions for what parts of the program you need to implement.Buffer data structure, a stack type buffer (implemented by me) and a circular type buffer (which you will implement). At the beginning of the ProducersConsumers.c program there is an #include directive that chooses which buffer implementation to use. The following header file defines an array-based stack buffer (a Last-In-First-Out buffer).
ProducersConsumers.c to use circular buffers instead of stack buffers by changing only which header file is included into ProducersConsumers.c . Everything else in ProducersConsumers.c is independent of which kind of buffer is being used (this is because StackBuffer.h and CircularBuffer.h are two different implementations of the same "abstract data type").
When you work on this, first get the When you get this version of the producer-consumer problem working, you should notice that it is prone to deadlocks (when you run the program, it sometimes seems to stop several seconds before the message "Threads stopped." gets printed in the console window; that is the deadlock). Write up a brief explanation of what is causing the deadlock. Is there an easy way to avoid this particular deadlock situation?
Turn in a zip file containing your explanation of the deadlock problem and your versions of the This assignment is due Monday, April 4. Here are links to some Win32 API functions that you will need to use in this assignment. Here are a few more MSDN references. These are not directly related to this assignment, but you might find them informative. |