# Take Semaphore before starting tasks

**URL:** <https://forums.freertos.org/t/take-semaphore-before-starting-tasks/1499>\
**Category:** Kernel\
**Created:** [September 23, 2014, 10:22am UTC](https://forums.freertos.org/t/take-semaphore-before-starting-tasks/1499 "2014-09-23T10:22:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 23, 2014, 10:22am UTC](https://forums.freertos.org/t/take-semaphore-before-starting-tasks/1499/1 "2014-09-23T10:22:59Z")

</div>

**[chaabanemalki](https://sourceforge.net/u/chaabanemalki/)** wrote on [Tuesday, September 23, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/44c40fb9/#a76a):

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)😉 in the first task that will run.

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

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 23, 2014, 10:29am UTC](https://forums.freertos.org/t/take-semaphore-before-starting-tasks/1499/2 "2014-09-23T10:29:14Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 23, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/44c40fb9/#a76a/0db3):

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

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 23, 2014, 11:19am UTC](https://forums.freertos.org/t/take-semaphore-before-starting-tasks/1499/3 "2014-09-23T11:19:00Z")

</div>

**[chaabanemalki](https://sourceforge.net/u/chaabanemalki/)** wrote on [Tuesday, September 23, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/44c40fb9/#6799):

I use only vSemaphoreCreateBinary().  
Thank u

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 23, 2014, 11:25am UTC](https://forums.freertos.org/t/take-semaphore-before-starting-tasks/1499/4 "2014-09-23T11:25:46Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 23, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/44c40fb9/#6799/c97d):

> 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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 23, 2014, 11:49am UTC](https://forums.freertos.org/t/take-semaphore-before-starting-tasks/1499/5 "2014-09-23T11:49:01Z")

</div>

**[chaabanemalki](https://sourceforge.net/u/chaabanemalki/)** wrote on [Tuesday, September 23, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/44c40fb9/#187a):

Thank you, that clears everything
