Parallel Programming - Producer Consumer problem

> (Data|State) Management and Processing > (Concurrency | Parallel | Asynchronous) programming

1 - About

The producer–consumer problem (also known as the bounded-buffer problem) is a classic example of a multi-process synchronization problem.

The problem describes two processes who share a common, fixed-size buffer used as a queue.

  • the producer
  • and the consumer


  • The producer's job is to generate a piece of data, put it into the buffer and start again.
  • The consumer (at the same time) is consuming the data (i.e., removing it from the buffer) one piece at a 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.

The solution can be reached by means of inter-process communication, typically using semaphores.

An inadequate solution could result in a deadlock where both processes are waiting to be awakened.


3 - Documentation / Reference