Your queue has no limit, and nothing ever says no
transcript
Orders arrive faster than you can price them. So where do the extra orders wait? And for how long?
A shared list. The producer made 1,000 orders. Before the consumer started. Peak depth, 1,000. And the consumer polls an empty list every millisecond.
Put a bounded queue between them. It holds two orders at most. Producers wait when it's full. The system pushes back. Consumers wait when it's empty.
When it's full, you choose. Wait. The producer slows to the consumer. Or drop and count, for work you can redo. Or refuse with a busy answer. Growing is not a choice. A queue with no limit is a leak.
One more rule. Check the condition in a loop. Another thread may have taken your spot first.
A queue with no limit isn't a queue. It's a leak. Say the limit. And say what happens at it.
Full breakdown in the lecture.