Quality RTOS & Embedded Software

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


xQueueReceive return value

Posted by rrrum on June 27, 2015

After queue is created and then used to receive with Maximum delay parameter as in example bellow:

xStatus = xQueueReceive( xReceiveTestprocess, &evt, portMAX_DELAY);

if(xStatus == pdPASS ){ ... }

I would like to optimize code. Should return value always be tested for pdPASS before processing received data as shown in some examples? I mean xQueueReceive can ever return errQUEUE_EMPTY if maximum delay is specified? What do you recommend? Thanks

xQueueReceive return value

Posted by rtel on June 27, 2015

If you block indefinitely using portMAX_DELAY then you don't need to check the return value because, as you say, it will only return if data was received.

Although lots of examples use infinite block times for simplicity, it is not recommended to use infinite delays in real code is they offer no neat method of recovering from errors (for example if something had happened that meant data was never posted to your queue the task would carry on blocking indefinitely so you would need another task to check for the error condition).

Note portMAXDELAY is only an infinite block time if configINCLUDEvTaskSuspend is set to 1.


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

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

Latest News

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

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

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

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