title: How to know which task has taken a binary semaphore?
body: <p>I have three tasks, which shares a binary semaphore <code>myBinarySemaphore</code>. I'd like to know which task is currently having the binary semaphore. I could use a global variable to do this but does freeRTOS provide a method for this ?</p>
  <p>Here's the code, I'm looking for a freeRTOS method to check which task has the binarySemaphore, in <code>taskC</code> for example. <code>xTaskOwner</code> is pure invention for example purpose. Thanks.</p>
  <pre class="lang-c prettyprint-override"><code>    void taskA(void *pvParameters)
      {
          for(;;)
          {
              if(xSemaphoreTake(myBinarySemaphore, (TickType_t) 10) == pdTRUE)
              {
                  xSemaphoreGive(myBinarySemaphore);
              }
          }
      }
      
      void taskB(void *pvParameters)
      {
          for(;;)
          {
              if(xSemaphoreTake(myBinarySemaphore, (TickType_t) 10) == pdTRUE)
              {
                  xSemaphoreGive(myBinarySemaphore);
              }
          }
      }
      
      void taskC(void *pvParameters)
      {
          for(;;)
          {
              if(xTaskOwner(myBinarySemaphore) == taskA) // &lt;== How to check with freeRTOS which task has the semaphore ? 
                  printf(&quot;taskA has the semaphore&quot;);
              else if (xTaskOwner(myBinarySemaphore) == taskB)
                  printf(&quot;taskB has the semaphore&quot;);
          }
      }
  </code></pre>
  <p><strong>PS &amp; EDIT</strong>: let's assume that taskC can be run simultaneously than the other tasks, because otherwise my example is wrong.</p>