# RTOS V3.22 Semaphore does not work properly??

**URL:** <https://forums.freertos.org/t/rtos-v3-22-semaphore-does-not-work-properly/2332>\
**Category:** Kernel\
**Created:** [April 29, 2008, 1:36pm UTC](https://forums.freertos.org/t/rtos-v3-22-semaphore-does-not-work-properly/2332 "2008-04-29T13:36:44Z")\
**Posts on this page:** 2\
**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:** [April 29, 2008, 1:36pm UTC](https://forums.freertos.org/t/rtos-v3-22-semaphore-does-not-work-properly/2332/1 "2008-04-29T13:36:44Z")

</div>

**[narayan\_ak](https://sourceforge.net/u/narayan_ak/)** wrote on [Tuesday, April 29, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/68502c9c/#edf7):

Dear all,  
I have a situation which I am trying to undertand. The scenario is something like below.

I have two tasks task\_A and task\_B  
A binary semaphore ABC is created.

task\_A( )  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delay 100ticks  
}

task\_B( )  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delay 100ticks  
}

A( )  
{  
if(xSemaphoreTake( ABC, portMAX\_DELAY ) == pdTRUE )  
&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // do something  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xSemaphoreGive( ABC );  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; taskdelay (25 ms; //Note delay here  
&nbsp;&nbsp; }  
&nbsp;&nbsp; else  
&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Task A Error");  
&nbsp;&nbsp; }  
}

B( )  
{  
if(xSemaphoreTake( ABC, portMAX\_DELAY ) == pdTRUE )  
&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // do something  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xSemaphoreGive( ABC );&nbsp; //Note NO delay here  
}  
&nbsp;&nbsp; else  
&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Task B Error");  
&nbsp;&nbsp; }  
}

My setup is configured as 32bits, thereofre portMAX\_DELAY will be large. However I see that I get errors "Task B Error".(and Task A error sometimes) Is it possible that the sempahore is timing out even with portMAX\_DELAY or am I doing sonmething wrong here?  
Any insight will be appreciated. At he moment my workaround is while ((xSemaphoreTake( ABC, portMAX\_DELAY ) != pdTRUE ), but I wnat to know what is wrong.  
-regards  
Narayan

---

<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:** [April 29, 2008, 1:57pm UTC](https://forums.freertos.org/t/rtos-v3-22-semaphore-does-not-work-properly/2332/2 "2008-04-29T13:57:40Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, April 29, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/68502c9c/#edf7/8302):

Its difficult to say, as you are using a rather old version (there have been 23 updates since V3.2.2!).&nbsp; There were some situation where a premature unblock was possible, and under certain circumstances the outer == TRUE was required, but I think this was to do with multiple tasks and interrupts accessing the same queue/semaphore.&nbsp; Do you have anything else accessing the semaphore, or just these tasks?

Can you update to a newer version?

Regards.
