Bird
0
0

Given this code snippet, what will be the output if the queue is empty and workerTask blocks on xQueueReceive?

medium📝 Predict Output Q4 of 15
FreeRTOS - Design Patterns for RTOS
Given this code snippet, what will be the output if the queue is empty and workerTask blocks on xQueueReceive?
void workerTask(void *params) {
  int workItem;
  while(1) {
    if(xQueueReceive(workQueue, &workItem, portMAX_DELAY) == pdPASS) {
      printf("Processed %d\n", workItem);
    }
  }
}
AThe task prints garbage values continuously
BThe task immediately prints zero and continues looping
CThe task waits indefinitely until a work item arrives, then prints it
DThe task crashes due to null pointer
Step-by-Step Solution
Solution:
  1. Step 1: Understand xQueueReceive with portMAX_DELAY

    Using portMAX_DELAY causes the task to block indefinitely until an item is received.
  2. Step 2: Analyze output behavior

    The task prints "Processed " only after receiving a valid work item.
  3. Final Answer:

    The task waits indefinitely until a work item arrives, then prints it -> Option C
  4. Quick Check:

    Blocking on empty queue = waits until item [OK]
Quick Trick: portMAX_DELAY blocks task until queue item arrives [OK]
Common Mistakes:
  • Assuming immediate return with zero
  • Thinking task crashes on empty queue
  • Believing task prints garbage without data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes