Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like a semaphore implemented using busy waiting.</p> <p>It works as follows:</p> <p>The producer and the consumer are working parallel to each other. The mutex is for mutual exclusion. That means, that only one of them is accessing the incommon datastructure at the same time. down() is checking if the mutex is free (== 1 in this case). It is checking this in a while loop like: <code>while (mutex &lt; 1);</code>. If the mutex is finally free, it decreases its value (called "taking the mutex").</p> <p>The other two semaphores are for making sure two things:</p> <ol> <li>a consumer can only consume, if the datastructure is not empty</li> <li>a producer can only produce, if the datastructure is not full</li> </ol> <p>This is necessary because one of both can be faster than the other one.</p> <p>With <code>down(&amp;empty);</code> the producer checks if there are empty slots in the datastructure. If this is not the case he is not allowed to produce yet (busy waiting until a slot is free, meaning empty > 0). Otherwise he decreases empty and continues. When he added his produced item in the datastructure he incereases the value of full slots with <code>up(&amp;full);</code>.</p> <p>With <code>down(&amp;full);</code> the consumer checks if there are full slots to read. If this is not the case he is not allowed to read yet (busy waiting until a slot is full, meaning full > 0). Otherwise he decreases full and continues. When he consumed his item from the datastructure he increases the value of empty slots.</p> <p>Changing the order of ups and downs could cause a deadlock, because they could be waiting for each other infinitely long.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload