Bird
0
0

Given the code snippet:

medium📝 Predict Output Q4 of 15
FreeRTOS - Interrupt Management
Given the code snippet:
taskENTER_CRITICAL();
sharedCounter++;
taskEXIT_CRITICAL();
What is the effect of this code on sharedCounter in a multitasking environment?
AsharedCounter may be corrupted due to interrupts
BsharedCounter is safely incremented without interruption
CsharedCounter is reset to zero
DsharedCounter increment is delayed indefinitely
Step-by-Step Solution
Solution:
  1. Step 1: Analyze critical section usage

    taskENTER_CRITICAL() disables interrupts, preventing context switches during increment.
  2. Step 2: Effect on sharedCounter

    Increment happens atomically, so sharedCounter is safely updated without corruption.
  3. Final Answer:

    sharedCounter is safely incremented without interruption -> Option B
  4. Quick Check:

    Critical section ensures safe increment = True [OK]
Quick Trick: Critical sections make increments atomic and safe [OK]
Common Mistakes:
  • Assuming interrupts still occur inside critical section
  • Thinking sharedCounter resets automatically
  • Believing increment is delayed indefinitely

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes