Bird
0
0

Find the bug in this shutdown notification code:

medium📝 Debug Q7 of 15
FreeRTOS - Design Patterns for RTOS
Find the bug in this shutdown notification code:
void Task(void *pvParameters) {
  for (;;) {
    ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
    if (shutdownRequested) {
      break;
    }
  }
  vTaskDelete(NULL);
}
AportMAX_DELAY causes infinite wait, blocking shutdown
BvTaskDelete(NULL) should be outside the loop
CshutdownRequested is not updated inside the loop
DpdFALSE should be pdTRUE to clear notification count
Step-by-Step Solution
Solution:
  1. Step 1: Understand ulTaskNotifyTake parameters

    First parameter pdTRUE clears notification count on exit; pdFALSE does not.
  2. Step 2: Identify impact of pdFALSE here

    Not clearing notification causes ulTaskNotifyTake to return immediately repeatedly, causing busy loop.
  3. Final Answer:

    pdFALSE should be pdTRUE to clear notification count -> Option D
  4. Quick Check:

    Clear notification with pdTRUE to avoid busy loop [OK]
Quick Trick: Use pdTRUE to clear notification count after take [OK]
Common Mistakes:
  • Using pdFALSE causing repeated immediate returns
  • Misunderstanding portMAX_DELAY usage
  • Ignoring notification clearing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes