Bird
0
0

Given the code below, what will happen when Task2 calls xTaskNotifyGive(Task1Handle); while Task1 is blocked on ulTaskNotifyTake(pdTRUE, portMAX_DELAY);?

medium📝 Predict Output Q4 of 15
FreeRTOS - Task Notifications
Given the code below, what will happen when Task2 calls xTaskNotifyGive(Task1Handle); while Task1 is blocked on ulTaskNotifyTake(pdTRUE, portMAX_DELAY);?
void Task1(void *pvParameters) {
    ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
    // Execution resumes here
}

void Task2(void *pvParameters) {
    xTaskNotifyGive(Task1Handle);
}
ATask1 unblocks and continues execution immediately.
BTask2 blocks until Task1 calls ulTaskNotifyTake again.
CTask1 ignores the notification and remains blocked.
DTask2 causes a runtime error due to invalid notification.
Step-by-Step Solution
Solution:
  1. Step 1: Understand ulTaskNotifyTake()

    This function blocks the task until a notification is received.
  2. Step 2: Effect of xTaskNotifyGive()

    Calling xTaskNotifyGive() sends a notification to Task1, unblocking it.
  3. Final Answer:

    Task1 unblocks and continues execution immediately. -> Option A
  4. Quick Check:

    Notification unblocks waiting task [OK]
Quick Trick: xTaskNotifyGive unblocks ulTaskNotifyTake [OK]
Common Mistakes:
  • Assuming Task2 blocks
  • Thinking notification is ignored
  • Believing runtime error occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes