Back to problems

Implement a Blocking Producer-Consumer Queue

Object-Oriented Programming · Apple · Medium

Monitor Pattern: One Lock, Two Condition Variables The heart of this problem is coordination, not data structure design. A plain FIFO buffer (a linked list or a deque) already gives us ordering; what we must add is a guarantee that two kinds of threads never step on each other and never spin wastefully. A producer that finds the buffer full has nothing useful to do until some consumer frees a slot, and a consumer that finds it empty has nothing to do until a producer adds an…

Loading the rest of the question…