Query about task deletion

killer414 wrote on Saturday, April 16, 2011:

I had a basic query about task deletion in freertos. Can we delete a task from within a task? as in last line will be the vTaskDelete call… What argument do you pass?
Also the documentation says that the memory for the deleted task is only deleted when the idle task is run… Is there any other way to do this?

rtel wrote on Saturday, April 16, 2011:

A task can delete itself by calling either

vTaskDelete( NULL );

or

vTaskDelete( my_handle ),

where my_handle is a variable of type xTaskHandle that holds the calling tasks handle.

The memory allocated to the task for the task stack and task control block are freed the next time the idle task runs.  That is currently the only way it is done.

Regards.

rtel wrote on Saturday, April 16, 2011:

Reading your question again - if you mean can one task delete another task (rather than itself), then “yes” it can.  The parameter to vTaskDelete() is the handle of the task you are deleting.  Task handles can be obtained using the last parameter of the xTaskCreate() call used to create the task in the first place.

Regards.

killer414 wrote on Saturday, April 16, 2011:

Thanks for that… Maybe an api call to delete allocated memory in a future release ? :slight_smile: