This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Semaphores for 1 resource and multiple tasks

Other Parts Discussed in Thread: SYSBIOS

Dear all,

the SYSBIOS guide states:

Binary semaphores are either available or unavailable. Their value cannot be incremented beyond 1.
Thus, they should be used for coordinating access to a shared resource by a maximum of two tasks.

Counting semaphores keep an internal count of the number of corresponding resources available. When
count is greater than 0, tasks do not block when acquiring a semaphore. The maximum count value for
a semaphores plus one is the number of tasks a counting semaphore can coordinate.

The semaphore count is initialized to count when it is created. In general, count is set to the number of
resources that the semaphore is synchronizing

What if I have one resource shared among several tasks? I assume using a binary semaphore is fine and the tasks pending on the semaphore will all stop. Am I missing something?

  • Hi Leonardo,

    I think the documentation is a bit misleading in this case. Yes, you should be able to use a binary semaphore as a mutex for a shared resource, and call Semaphore_pend in multiple tasks. When the count is 0, the tasks will be blocked and queued until Semaphore_post is called, at which point the first task on the semaphore queue will be made ready. Binary only means the semaphore count will not go beyond 1.

    Best regards,
    Vincent