Bird
0
0

Examine the following worker task code snippet. What is the main issue that could cause incorrect processing?

medium📝 Debug Q6 of 15
FreeRTOS - Design Patterns for RTOS
Examine the following worker task code snippet. What is the main issue that could cause incorrect processing?
void workerTask(void *params) {
  int workItem;
  while(1) {
    xQueueReceive(workQueue, &workItem, 0);
    printf("Processed %d\n", workItem);
  }
}
AThe task does not delete itself after processing
BThe workItem variable is not initialized before use
CxQueueReceive is called with zero block time, causing missed items if queue is empty
DThe printf statement is inside the loop causing performance issues
Step-by-Step Solution
Solution:
  1. Step 1: Analyze xQueueReceive usage

    Calling xQueueReceive with zero block time returns immediately if no item is available.
  2. Step 2: Consequence of zero block time

    If the queue is empty, workItem is not updated but printf still prints the old or garbage value.
  3. Final Answer:

    xQueueReceive is called with zero block time, causing missed items if queue is empty -> Option C
  4. Quick Check:

    Zero block time can cause missed data [OK]
Quick Trick: Non-blocking receive may skip items [OK]
Common Mistakes:
  • Assuming workItem is always valid after receive
  • Ignoring the need to check xQueueReceive return value
  • Thinking task deletion is required here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes