Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


waiting portMAX_DELAY

Posted by rrrum on May 23, 2016


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?


waiting portMAX_DELAY

Posted by rtel on 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...portMAXDELAY is only an indefinite delay if INCLUDEvTaskSuspend is set to 1. The code snippet you show probably has INCLUDEvTaskSuspend set to 0, in which case portMAXDELAY will be a block time of 0xffffffff or 0xffff, depending on whether configUSE16BIT_TICKS is set to 0 or 1.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo & Nuvoton Cortex-M23 demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner