waiting portMAX_DELAY

rrrum wrote on Monday, May 23, 2016:

Hello,

In various examples of waiting on some event (semaphore, queue) I see that someone is using while (very often in sys_arch.c of lwip), i.e.:

while( xSemaphoreTake( *pxSemaphore, portMAX_DELAY ) != pdTRUE );

Is it really necessary? Is it just coding style? What is the reason if portMAX_DELAY macro should wait indefinitely?

rum

rtel wrote on Monday, May 23, 2016:

A couple of points:

  1. A lot of examples we provide use indefinite delays. This is done for
    convenience and to ensure the examples are kept as simple as possible.
    However, in real applications indefinite delays are rarely a good idea
    as they do not provide an opportunity to correct erroneous conditions if
    the event being waited for never occurs.

  2. …and in answer to your question…portMAX_DELAY is only an
    indefinite delay if INCLUDE_vTaskSuspend is set to 1. The code snippet
    you show probably has INCLUDE_vTaskSuspend set to 0, in which case
    portMAX_DELAY will be a block time of 0xffffffff or 0xffff, depending on
    whether configUSE_16_BIT_TICKS is set to 0 or 1.