Bird
0
0

Find the problem in this FreeRTOS idle hook code:

medium📝 Debug Q7 of 15
FreeRTOS - Task Scheduling

Find the problem in this FreeRTOS idle hook code:

void vApplicationIdleHook(void) {
static int counter = 0;
counter++;
if(counter > 1000000) {
counter = 0;
}
}

ACounter variable may overflow causing undefined behavior
BIdle hook should not use static variables
CIdle hook must call vTaskDelay to avoid CPU hogging
DNo problem; code is safe and correct
Step-by-Step Solution
Solution:
  1. Step 1: Analyze static variable usage

    Static variables retain value across calls and are safe here for counting.
  2. Step 2: Check for overflow risk

    Integer overflow is unlikely here because counter resets before exceeding int max.
  3. Final Answer:

    No problem; code is safe and correct -> Option D
  4. Quick Check:

    Static counter with reset is safe in idle hook = D [OK]
Quick Trick: Static counters with reset avoid overflow in idle hook [OK]
Common Mistakes:
  • Assuming static variables cause overflow
  • Thinking idle hook must call delay
  • Believing static variables are forbidden

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes