Quality RTOS & Embedded Software

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


vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by pronkin on October 24, 2013

Hi everybody, for one of my project I use Cooperative Multi-threading (configUSE_PREEMPTION = 0)

And think that vTaskSuspendAll and xTaskResumeAll are useless in this case Since xTaskResumeAll may cause YIELD and I use heap_3 Malloc scheme

pvReturn = malloc( xWantedSize );
traceMALLOC( pvReturn, xWantedSize );
xTaskResumeAll(); //It can YIELD here

It means pvPortMalloc can cause a context switch (little confusing)

Here is some bad scenario: 1) Some work with critical data structures 2) Decide to malloc some memory, while data structures not correct 3) After pvPortMalloc other task can get access to wrong data 4) End work with critical data structures and free memory

Maybe in case of configUSE_PREEMPTION = 0 vTaskSuspendAll and xTaskResumeAll should be empty?

vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by edwards3 on October 24, 2013

Initial thought is to keep them, but to just not yield if configUSE_PREEMPTION is 0, but second thought is you might be right to just compile them out all together.

When the RTOS is suspended interrupts can happen but context switches cant, but if you are using cooperative scheduling then context switches are not going to happen anyway.

But even when configUSE_PREEMPTION is 0 a context switch can happen if you for example send to a queue and there is a task blocked on the queue - but that is more expected behavior whereas calling resumeAll and getting a context switch isnt.

vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by pronkin on October 24, 2013

hm, yes vTaskSuspendAll can be used in cooperative sheduller to avoid context switch in QueueSend or SemaphoreGive, so vTaskSuspendAll can't be empty. But context switch in pvPortMalloc not expected (for me)

vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by richardbarry on November 7, 2013

Take a look at the head revision in SVN - the co-operative behaviour has been changed, and as such it will probably be released as V7.6.0.

Now a context switch is only performed if the calling task is blocked. For example, if you attempt to write to a queue with a block time specified and the queue is full then the task will block and another task will start running. However, if you successfully write to the queue, and writing to the queue causes a task of higher priority to unblock, then a context switch will not occur - the original task will continue executing until it either blocks or calls taskYIELD().

Likewise when changing the priority of another task, or unsuspending another task, etc. A context switch will not occur even if the API call makes a higher priority task ready to run.


[ 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.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

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