Quality RTOS & Embedded Software

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


calling vTaskDelete when in critical section

Posted by mizer on April 2, 2009

In case it matters I'm using the AVR32 UC3A port.

While in one task I'm calling vTaskDelete to delete a different task. It happens my code to make the vTaskDelete call is within a short taskENTER_CRITICAL section. I see at the end of the vTaskDelete function a taskYield request. My code would still have this within a taskCRITICAL section (due to the nested taskCRITICAL calls). Is this okay?

As I think about this further ... it seems the act of the taskYIELD call (at the end of the vTaskDelete function) could actually cause a context switch and therefore defeat the purpose of my CRITICAL section. But since we are in a CRITICAL section [by my doing] no event (an interrupt) could've taken place that would set up an an actual task yield. I think the task yield section at the end of the vTaskDelete function is primarily for when a task deletes itself (because I suspect you never return from the vTaskDelete function in that case).

So the first paragraph is my real question.

Any comments appreciated.

I sure am enjoying freeRTOS. Seriously!


RE: calling vTaskDelete when in critical sect

Posted by Richard on April 3, 2009
The Yield at the end of vTaskDelete() is to ensure you yield away from the task that has now been deleted, as it (conceptually) no longer exists (assuming you are deleting the running task rather another task).

Some ports will yield immediately and some will hold it pending until you exit the critical section - I cannot remember off hand which the AVR32 port does. If it yields immediately then any code you place between deleting the task and exiting your critical section will never run because the task will have yielded to another task and never run again (again this assumes you are deleting the running task rather than another task).


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

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

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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