After some comment, I finally post an answer, but I realize that it may be useful to explain a bit more with some schema.
If the producer run 2x faster than the consumer the number of element in the Fifo will grow linearly. So as in the real life, we have to specify a limited stock size. So that if the stock is full, the producer must wait.
That can be achieve with a dual synchronization:
- Consumer wait if the fifo is empty and is awake if an element is pushed.
- Producer wait if the fifo is full and is awake if an element is remove so that the size goes under the threshold.
Aucun commentaire :
Enregistrer un commentaire