Bird
0
0

Consider the following FreeRTOS task code:

medium📝 Predict Output Q4 of 15
FreeRTOS - Design Patterns for RTOS
Consider the following FreeRTOS task code:
void Task(void *pvParameters) {
  for (;;) {
    if (ulTaskNotifyTake(pdTRUE, 0)) {
      printf("Shutdown signal received\n");
      break;
    }
    printf("Task running\n");
    vTaskDelay(pdMS_TO_TICKS(100));
  }
}
What will be printed if the shutdown notification is sent to this task?
ANo output will be printed
BShutdown signal received only
CTask running repeatedly without stopping
DTask running\nShutdown signal received
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop behavior

    The task prints "Task running" each iteration until ulTaskNotifyTake returns non-zero.
  2. Step 2: On notification

    When shutdown notification arrives, ulTaskNotifyTake returns true, prints "Shutdown signal received", then breaks loop.
  3. Final Answer:

    Task running\nShutdown signal received -> Option D
  4. Quick Check:

    Prints running then shutdown message [OK]
Quick Trick: Notification breaks loop after one last print [OK]
Common Mistakes:
  • Assuming only shutdown message prints
  • Ignoring the initial 'Task running' prints
  • Thinking no output occurs on notification

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes