Posts

Showing posts from April, 2020

Producer-Consumer Determinism

The Producer-Consumer pattern is a common pattern used in concurrent programming. In this model one task writes values to a fixed length buffer and another task reads values from the fixed length buffer. There are many variations on the Producer-Consumer pattern, mostly dealing with various numbers of producers and various numbers of consumers. This article will use a simple Producer-Consumer pattern with a single producer and a single consumer.   Determinism The Producer-Consumer pattern has some simple limitations. The Consumer task cannot read data from an empty buffer and the Producer task cannot write data to a full buffer. These limitations might lead the programmer to assume that the Producer and Consumer will spend their time alternately reading and writing the buffer. First the Producer will write a value then the Consumer will read a value. While the general idea is correct, the actual viewed results may be a bit confusing. Non-Deterministic Example ...