Quality RTOS & Embedded Software

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


vTaskSuspendAll() Critical Section

Posted by Ivan on May 11, 2011
Hi all,

For this function:

void vTaskSuspendAll( void )
/* A critical section is not required as the variable is of type
portBASE_TYPE. */

This is generated as a multi-line assembly code and can be interrupted. I was just wondering, why in this case will we not need a critical section? Just because it is of portBASE_TYPE?

Thanks in advance. Cheers!

RE: vTaskSuspendAll() Critical Section

Posted by Dave on May 12, 2011
That is what is says, in the code that you have posted.

RE: vTaskSuspendAll() Critical Section

Posted by Richard Damon on May 14, 2011
The idea is that FreeRTOS assumes that the actually increment will be atomic.

Even if not, vTaskSuspendAll is only called at task level (it doesn't have FromISR) so no interrupt will affect the variable itself. If the increment is not atomic, then it turns out that it doesn't cause problems in this case. If the interrupt occurs after the write of the new value, it will see the new value, if it occurs before, if the old number wasn't zero, no task switch will occur, and since the interrupt doesn't change the value it will return with out task switching (since the number isn't zero) or changing the value. If the number was zero before, and thus seen as zero by the interrupt, a task switch might occur, but if it dose, the value now in uxSchedulerSuspended when the task gets switched back in is by definition 0, the same as before, so no harm in the non-atomic access interrupt by a task switch.

RE: vTaskSuspendAll() Critical Section

Posted by Ivan on May 19, 2011
Thanks loads for the clear explanation. I came to realization that FreeRTOS had wanted for the compiler to compile into atomic machine code that reads, updates and write at one go. Subsequently, I ran through a couple of test cases like you mentioned and found that they were still safe.

Once again, thank you very much for helping me understand.

Warmest Regards :)

[ 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