RTOS V3.22 Semaphore does not work properly??

Posted by Narayan on April 29, 2008
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( )
{
A();
delay 100ticks
}

task_B( )
{
B();
delay 100ticks
}


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

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

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

RE: RTOS V3.22 Semaphore does not work properly??

Posted by Richard on April 29, 2008
Its difficult to say, as you are using a rather old version (there have been 23 updates since V3.2.2!). 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. Do you have anything else accessing the semaphore, or just these tasks?

Can you update to a newer version?

Regards.