Bird
0
0

Given this code snippet:

medium📝 Debug Q14 of 15
FreeRTOS - Task Creation and Management
Given this code snippet:
TaskHandle_t xHandle = NULL;
xTaskCreate(TaskFunction, "Task", 1000, NULL, 1, &xHandle);
vTaskDelete(xHandle);

What is the problem with this code?
AThe task handle is NULL, so deletion fails.
BThe task is deleted but not removed from the scheduler.
CvTaskDelete() requires NULL to delete the current task only.
DDeleting a task immediately after creation may cause undefined behavior.
Step-by-Step Solution
Solution:
  1. Step 1: Understand task creation and immediate deletion

    The task is created and its handle stored in xHandle. Immediately deleting it may cause issues if the task has not started or scheduler not running.
  2. Step 2: Recognize timing and scheduler state

    Deleting a task before the scheduler runs or before the task starts can cause undefined or unexpected behavior.
  3. Final Answer:

    Deleting a task immediately after creation may cause undefined behavior. -> Option D
  4. Quick Check:

    Delete right after create = possible undefined behavior [OK]
Quick Trick: Avoid deleting tasks immediately after creation before scheduler runs [OK]
Common Mistakes:
  • Assuming NULL only deletes current task (it can delete any valid handle)
  • Ignoring scheduler state before deleting tasks
  • Thinking deletion does not remove task from scheduler

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes