Take Semaphore before starting tasks

chaabanemalki wrote on Tuesday, September 23, 2014:

Hello,
Since I started using FreeRTOS I had this weird behavior ( or it’s normal).
I create a semaphore (Rx_Semaphore), then i use this semaphore to block a task (Task0) with it.
And another task (task1) to give Rx_Semaphore.
When I run my code, Task0 takes Rx_Semaphore even if task1 didn’t give Rx_Semaphore yet.
The solution I use is to take Rx_Semaphore (xSemaphoreTake(Rx_Semaphore ,0):wink: in the first task that will run.

Is this a normal behavior or I’m missing something ?

rtel wrote on Tuesday, September 23, 2014:

That would depend on which function you were using to create the semaphore.

Regards.

chaabanemalki wrote on Tuesday, September 23, 2014:

I use only vSemaphoreCreateBinary().
Thank u

rtel wrote on Tuesday, September 23, 2014:

I use only vSemaphoreCreateBinary().

If you look at the vSemaphoreCreateBinary() macro you will see the
initial state for the semaphore.

Assuming you are using a recent version of FreeRTOS it is recommended to
use xSemaphoreCreateBinary() in place of vSemaphoreCreateBinary(). When
using the ‘x’ function rather than the ‘v’ macro the semaphore will not
be available until it has first been given.

Regards.

chaabanemalki wrote on Tuesday, September 23, 2014:

Thank you, that clears everything