6. ConcurrencyProducer–consumer
Producer–consumer
Producer–consumer is a pattern where some threads create work and others process it, with a queue between them so neither waits on the other directly. A web server accepting requests and a pool of workers handling them is a typical example. The queue is usually bounded, with a maximum size, because if producers outpace consumers an unbounded queue just grows until memory runs out. When it fills up you have to choose: make producers wait, drop work, or reject it with an error. That choice is called backpressure, and it’s how a slow part of a system pushes back on a fast one instead of falling over.
In this lesson: A bounded queue with producer and consumer rate sliders, plus a thread pool.