Producer-consumer

Producer-consumer problem is a classic example of a problem, which requires multiple threads/processes synchronization. It describes two threads – the producer and the consumer. The producer creates a data and puts it into a fixed-size buffer and the consumer reads and removes it from the buffer.

To solve this problem, access to the buffer needs to be synchronized. Otherwise the consumer could try to read from an empty buffer or the producer could try to write to a full buffer. The following implementation extends the problem to multiple producers & consumers and uses condition_variables (C++11) to solve it.

Read more on wikipedia.

Source code