Glossary · Automation software engineering and architecture
Producer-consumer pattern
Also known as: Producer-consumer problem, Bounded buffer
German: Erzeuger-Verbraucher-Muster
In concurrent programming, the producer-consumer pattern decouples tasks that produce data from tasks that consume it through a shared buffer or queue, with synchronization ensuring that producers wait when it is full and consumers wait when it is empty.
- Software engineering
In one sentence
The producer-consumer pattern links data-producing and data-consuming tasks through a synchronized shared buffer or queue.
Example
The camera acquisition task produces images into a ring buffer, and the inspection task consumes them at its own pace without blocking acquisition.
How it applies
- Engineering: The pattern smooths out rate differences between tasks. Designers define the buffer size and the policy when it is full: block the producer, drop the oldest data or drop the newest.
- Real-time systems: A time-critical producer must not block. In that case lock-free buffers such as a Ring buffer with one producer and one consumer are used, and overruns are counted and reported.
- Documentation: If data can be dropped under load, document it, together with the diagnostic indicating that it happened, for example lost image frames in a vision system.
Producer-consumer vs. publish-subscribe
In producer-consumer, each data item is consumed once. In the Publish-subscribe pattern, every subscriber receives its own copy of each message.