Updated Jun 2025
vTaskDelete
task. h
1void vTaskDelete( TaskHandle_t xTask );
INCLUDE_vTaskDelete
Remove a task from the RTOS kernels management. The task being deleted will be removed from all ready, blocked, suspended and event lists.
NOTE: If a task deletes another task, the RTOS kernel allocated memory is freed in the API itself. If a task deletes itself, the idle task is responsible for freeing the RTOS kernel allocated memory. It is therefore important that the idle task is not starved of microcontroller processing time if your application makes any calls to
vTaskDelete()
See the demo application file death.c for sample code that utilises
vTaskDelete()
Parameters:
-
xTask
The handle of the task to be deleted. Passing NULL will cause the calling task to be deleted.
Example usage:
1void vOtherFunction( void )2{3 TaskHandle_t xHandle = NULL;45 // Create the task, storing the handle.6 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );78 // Use the handle to delete the task.9 if( xHandle != NULL )10 {11 vTaskDelete( xHandle );12 }13}