Quality RTOS & Embedded Software

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


how to clean up deleted task 's resource

Posted by vincent on February 19, 2013

i know that IDLE task is in charge of cleaning up deleted task's resource. however, IDLE task's priority is lower. it is possible that high priority task creates new task before IDLE task does it, if the FreeRTOS 's memory is lower, it may be fail to create new task. so, i wonder to know that there is a way to wake up IDLE task in running mode once one task is deleted ?


RE: how to clean up deleted task 's resource

Posted by Richard on February 19, 2013
First - it is very rare in small embedded systems that it is necessary to delete tasks. Generally in small dedicated systems all the resources (including tasks) are created during initialisation and then persist in the system until the system is turned off. You may therefore like to consider if there is an alternative to deleting the tasks in the first place.

Resources have to be cleaned by a task other than the task being deleted, hence it is done in the idle task. You could call the function used by the idle task to clean resources directly from another task, but that would require hacking the tasks.c file a bit as the function only has file scope.

If you really needed to you could temporarily raise the priority of the idle task (there is a function that allows you to get its handle) to the same priority as the task that wants to recreate a task - but be very careful doing that as the idle task never blocks so if you raise its priority too high you will not be able to recover and your application tasks will never run again.

Also, the function that creates a task returns a value that tells you if the task was created successfully or not, you could sit in a loop calling the xTaskCreate() function until it is successful if the only reason it is not successful is because a task that has been deleted has not yet been cleaned. Make sure to add a delay between each call to ensure the idle task has a chance to run though.


[ 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