The Producer Consumer problem describes two processes, the producer and the consumer, who share a common, fixed size buffer know as the queue.
- The producer creates the data and puts it into the buffer, and start again. And At the same time, the consumer consumes the data from the buffer one piece at a time.
- The problem here 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 for the producer is to either go to sleep or discard data if the buffer is full. And the next time the consumer removes an item from the buffer, it notifies the producer, who starts to fill the buffer again. In the same way, the consumer can go to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it notifies the consumer to start consuming the data again.