A producer is a concurrent component or thread that creates values and enters them into a shared queue. In a producer–consumer design, it coordinates with consumers through a bounded queue, mutex, and condition variables. section 16.3.2
Two producers and three consumers
A shared queue with capacity eight receives five values from each of two producer threads. Three consumers remove values concurrently; output shows insertion and removal order as scheduling varies.
Producer #1 Producer #2 Consumer #1 Consumer #2 Consumer #3
1 (1)
-1 (0)
2 (1)
-2 (0)
3 (1)
-3 (0)
4 (1)
-4 (0)
5 (1)
-5 (0)
6 (1)
7 (2)
-6 (1)
8 (2)
Done!
-7 (1)
-8 (0)
9 (1)
10 (2)
Done!
-9 (1)
-10 (0)
Done!
Done!
Done!
Browse an interleaved run showing producers filling the queue and consumers removing values. section 16.3.2







