Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
FreeRTOS - Task Priorities

What is wrong with this code snippet?

TaskHandle_t xTask;
vTaskPrioritySet(xTask, -1);
ACode is correct and will set priority to -1
BTask handle is not initialized
CPriority cannot be negative; this causes an error
DvTaskPrioritySet requires a delay parameter
Step-by-Step Solution
Solution:
  1. Step 1: Check task handle initialization

    TaskHandle_t xTask; is declared but not initialized (e.g., via xTaskCreate which sets the handle).
  2. Step 2: Consequence of uninitialized handle

    Passing uninitialized (garbage) handle causes undefined behavior or crash.
  3. Step 3: Check priority value

    Priority cannot be negative; passing -1 is invalid and causes error.
  4. Final Answer:

    Priority cannot be negative; this causes an error -> Option C
  5. Quick Check:

    Priority must be non-negative [OK]
Quick Trick: Priority values must be zero or positive [OK]
Common Mistakes:
  • Using negative priority values
  • Ignoring uninitialized task handle
  • Thinking delay parameter is needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes