Assume that we have two kinds of processes: producer and consumer. For now, we will have one from each of them.
Producer will produce information whereas consumer will consume the information. Both will continue their function infinitely. Two problems will be raised:
- The memory will be shared by both.
- Both do not know the size of the buffer.
The first problem would cause 202112061109 which would affect the follow-up execution by either the producer or the consumer.
The second problem will cause difficult troubles for producer and consumer. From the producer’s perspective, it might produce more information than needed or allowed which will cause memory out of bound. From the consumer’s perspective, it might continue its consumption even there is no information available which could result in undefined behaviour.
Neither of these problems are desirable.
Solution
To fix these, we have two solutions: