Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Updated Jun 2025

vTaskDelete

task. h

1void vTaskDelete( TaskHandle_t xTask );

INCLUDE_vTaskDelete
must be defined as 1 for this function to be available. See the RTOS Configuration documentation for more information.

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()
. Memory allocated by the task code is not automatically freed, and should be freed before the task is deleted.

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;
4
5 // Create the task, storing the handle.
6 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
7
8 // Use the handle to delete the task.
9 if( xHandle != NULL )
10 {
11 vTaskDelete( xHandle );
12 }
13}