Consider a FreeRTOS task that calls vTaskDelete(NULL); inside its own function. What is the expected behavior?
void TaskFunction(void *pvParameters) {
// Task code here
vTaskDelete(NULL);
// Code here will not run
}Think about what NULL means when passed to vTaskDelete().
Passing NULL to vTaskDelete() causes the currently running task to delete itself and stop executing immediately.
You want to delete a task other than the currently running one. Which value should you pass to vTaskDelete()?
Think about how FreeRTOS identifies tasks internally.
To delete a specific task, you must pass its task handle to vTaskDelete(). Passing NULL deletes the current task.
Examine the code below. Why does calling vTaskDelete(taskHandle); cause a runtime error?
TaskHandle_t taskHandle;
void Task1(void *pvParameters) {
// Task code
vTaskDelete(taskHandle);
}
void setup() {
xTaskCreate(Task1, "Task1", 1000, NULL, 1, &taskHandle);
}Check when taskHandle is assigned relative to its use.
The variable taskHandle is used inside the task before it is assigned by xTaskCreate. This causes an invalid handle to be passed to vTaskDelete, leading to a runtime error.
Given a task handle myTask, which code snippet correctly deletes the task?
Remember the type expected by vTaskDelete().
vTaskDelete() expects a task handle, not a pointer to a handle or dereferenced handle. Passing myTask directly is correct.
A task is blocked waiting for data on a queue. If vTaskDelete() is called on this task, what happens?
Consider how FreeRTOS handles task deletion regardless of state.
Deleting a task removes it immediately from the scheduler, even if it is blocked on a queue. The queue itself remains intact and unaffected.