Question on xSemaphoreTake()

Posted by Siheng Huang on January 7, 2009
I have a question on freeRTOS semaphore function:

xSemaphoreHandle xSemaphore,
portTickType xBlockTime

freeRTOS document says: “A block time of zero can be used to poll the semaphore”.
My question is what does the block time means and what happens after block time expires. There are two understandings:

1. The block time means the time period for task to poll the semaphore state. So after block time expires, the task continue to check if semaphore is available. If not, then task will check again after next block time expires.

2. The block is the max time task being block if the semaphore is not available. After block time expires, task will start to execute next instruction even if semaphore is not available.

Which understanding is correct?

if first understanding is correct, when using
xSemaphoreTake( xSemaphore, ( portTickType ) 0 ) in one of my task and the semaphore/mutex is not available for a long time, I guess the task being block continue to run trying to poll semaphore state? If so, will lower priority task be block? This seems to defeat the purpose of using semaphore.


RE: Question on xSemaphoreTake()

Posted by MEdwards on January 7, 2009
The block time is the maximum time the task will spend in the blocked state to wait for the semaphore. It does not execute at all when in the blocked state.

Take a look at the new book

RE: Question on xSemaphoreTake()

Posted by Siheng Huang on January 8, 2009
Thanks, MEdwards, that answers my question.