Three producers and each has a queue. Two consumers consume msg both from a specific queue and a common queue. How to synchronize them with pthread_cond?
Asked
Active
Viewed 36 times
1 Answers
0
The problem may need more exact specification. In general, just have the producers signal (for single consumer) or broadcast (in case of producer 3 with multiple consumers) when a queue becomes non-empty.
Consumers just work as fast as they can, going to sleep when the queues they read from are found empty. Protect all queue access inside critical sections.
If you need further clarification, add a comment and I will elaborate as needed.

Erik Alapää
- 2,585
- 1
- 14
- 25