Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>They are <strong>NOT</strong> the same thing. They are used for different purposes!<br> While both types of semaphores have a full/empty state and use the same API, their usage is very different. </p> <p><strong>Mutual Exclusion Semaphores</strong><br> Mutual Exclusion semaphores are used to protect shared resources (data structure, file, etc..). </p> <p>A Mutex semaphore is "owned" by the task that takes it. If Task B attempts to semGive a mutex currently held by Task A, Task B's call will return an error and fail.</p> <p>Mutexes always use the following sequence: </p> <pre> - SemTake - Critical Section - SemGive</pre> <p>Here is a simple example:</p> <pre> Thread A Thread B Take Mutex access data ... Take Mutex &lt;== Will block ... Give Mutex access data &lt;== Unblocks ... Give Mutex </pre> <p><strong>Binary Semaphore</strong><br> Binary Semaphore address a totally different question: </p> <ul> <li>Task B is pended waiting for something to happen (a sensor being tripped for example).</li> <li>Sensor Trips and an Interrupt Service Routine runs. It needs to notify a task of the trip.</li> <li>Task B should run and take appropriate actions for the sensor trip. Then go back to waiting.</li> </ul> <pre><code> Task A Task B ... Take BinSemaphore &lt;== wait for something Do Something Noteworthy Give BinSemaphore do something &lt;== unblocks </code></pre> <p>Note that with a binary semaphore, it is OK for B to take the semaphore and A to give it.<br> Again, a binary semaphore is NOT protecting a resource from access. The act of Giving and Taking a semaphore are fundamentally decoupled.<br> It typically makes little sense for the same task to so a give and a take on the same binary semaphore.</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. 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.
    3. VO
      singulars
      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