Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q14 of 15
FreeRTOS - Task Priorities

What is wrong with this code snippet?

TaskHandle_t xTask2 = NULL;
vTaskPrioritySet(xTask2, 4);
AThe function vTaskPrioritySet returns a value that is ignored.
BPriority 4 is invalid; priorities must be 0 or 1 only.
CvTaskPrioritySet requires a pointer to the task, not the handle.
DxTask2 is NULL, so setting priority causes undefined behavior.
Step-by-Step Solution
Solution:
  1. Step 1: Check the task handle value

    The variable xTask2 is set to NULL, meaning it does not point to a valid task.
  2. Step 2: Understand effect of NULL handle

    Calling vTaskPrioritySet() with a NULL handle leads to undefined behavior or runtime error because no valid task exists to change priority.
  3. Final Answer:

    xTask2 is NULL, so setting priority causes undefined behavior. -> Option D
  4. Quick Check:

    NULL task handle causes error [OK]
Quick Trick: Never pass NULL as task handle to vTaskPrioritySet [OK]
Common Mistakes:
  • Ignoring NULL task handle
  • Assuming priority range is only 0 or 1
  • Confusing handle with pointer to handle

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes