Bird
0
0

Given this code snippet, what is the expected behavior?

medium📝 Predict Output Q4 of 15
FreeRTOS - Task Notifications
Given this code snippet, what is the expected behavior?
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xTaskNotifyGiveFromISR(taskHandle, &xHigherPriorityTaskWoken);
if(xHigherPriorityTaskWoken) {
  portYIELD_FROM_ISR();
}
AThe ISR causes a deadlock by waiting for the task
BThe ISR blocks until the task processes the notification
CThe ISR notifies the task and yields if a higher priority task was woken
DThe notification is ignored if the task is already running
Step-by-Step Solution
Solution:
  1. Step 1: Understand xTaskNotifyGiveFromISR usage

    This function sends a notification from an ISR and sets xHigherPriorityTaskWoken if a higher priority task was woken.
  2. Step 2: Analyze portYIELD_FROM_ISR call

    If a higher priority task was woken, portYIELD_FROM_ISR requests a context switch to that task immediately.
  3. Final Answer:

    The ISR notifies the task and yields if a higher priority task was woken -> Option C
  4. Quick Check:

    Notify + yield if higher priority task woken [OK]
Quick Trick: Yield from ISR only if higher priority task is woken [OK]
Common Mistakes:
  • Assuming ISR blocks until task runs
  • Thinking notification is ignored if task runs
  • Believing ISR causes deadlock

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes