Bird
0
0

Identify the bug in this FreeRTOS consumer task code that causes it to never receive data:

medium📝 Debug Q14 of 15
FreeRTOS - Design Patterns for RTOS

Identify the bug in this FreeRTOS consumer task code that causes it to never receive data:

void consumerTask(void *params) {
    int receivedData;
    while(1) {
        if(xQueueReceive(queueHandle, &receivedData, 0) == pdFALSE) {
            // No data received
            continue;
        }
        processData(receivedData);
    }
}
AThe loop should use vTaskDelay instead of continue
BThe receive timeout is zero, causing missed data
CThe processData function is missing
DThe queue handle is not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Understand xQueueReceive timeout parameter

    A zero timeout means the call returns immediately if no data is available, possibly missing data if producer is slower.
  2. Step 2: Identify why data is never received

    Because the consumer never waits, it may loop too fast and miss data arriving slightly later.
  3. Final Answer:

    The receive timeout is zero, causing missed data -> Option B
  4. Quick Check:

    Timeout 0 means no wait = missed data [OK]
Quick Trick: Use non-zero timeout to wait for data [OK]
Common Mistakes:
  • Ignoring timeout effect on receive
  • Assuming missing queue handle causes this
  • Thinking processData absence causes no receive

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes