Hi everybody
I know that it is not recommended to use a task without an infinite loop but I just want to know which task deletes this task after reaching the end of function? does it delete itself or there is other tasks dedicated to do this for example idle task ?
A function that implements a task should never return (i.e., reach the end of the function), as there is nothing to return to. Depending on the port and if the configASSERT
is defined, it will trigger an assert (for example, in the case of Cortex M4 port, inside the prvTaskExitError
) if a function just returns. The task’s resources are not released.
If a task wants to exit, it should instead call vTaskDelete( NULL )
when its about to exit. In that case the idle task is responsible for freeing resources allocated for the task that have been deleted. Note that the idle task will only delete the memory allocated by the FreeRTOS scheduler for that task; it wont delete any memory/resources that the task istelf dynamically allocated/acquired during its runtime.