Concurrency

The Producer and Consumer Problem

gap-in-knowledge

The general statement is this: There are one or more producers generating some type of data (records, characters) and placing these in a buffer. There is a single consumer that is taking items out of the buffer one at a time. The system is to be constrained to prevent the overlap of buffer operations. That is, only one agent (producer or consumer) may access the buffer at any one time. The problem is to make sure that the producer won’t try to add data into the buffer if it’s full and that the consumer won’t try to remove data from an empty buffer.

Solutions to this problem and illustrate the power and the pitfalls of Semaphores.

We can define the producer and consumer functions as follows:

  • Structure of buffer

Using binary semaphores to attempt and implement this system:todo

Be able to explain all the different implementations and why it doesn't work!!

Demonstrated in textbook