Bird
0
0

Examine this FreeRTOS producer task snippet and identify the mistake:

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

Examine this FreeRTOS producer task snippet and identify the mistake:

void producerTask(void *params) {
  int data = 20;
  xQueueSend(queue, data, portMAX_DELAY);
  data = 30;
  xQueueSend(queue, &data, portMAX_DELAY);
  vTaskDelete(NULL);
}

AThe second xQueueSend call uses an incorrect block time parameter.
BThe first xQueueSend call passes data by value instead of by reference.
CvTaskDelete(NULL) should be called before sending data to the queue.
DThe variable 'data' should be declared as volatile.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the first xQueueSend call

    The function expects a pointer to the data to send, but 'data' is passed directly, which is incorrect.
  2. Step 2: Analyze the second xQueueSend call

    The second call correctly passes the address of 'data' (&data), which is the correct usage.
  3. Final Answer:

    The first xQueueSend call passes data by value instead of by reference. -> Option B
  4. Quick Check:

    Check parameter types for xQueueSend [OK]
Quick Trick: Always pass pointer to data in xQueueSend [OK]
Common Mistakes:
  • Passing data by value instead of pointer to xQueueSend
  • Misunderstanding block time parameter usage
  • Calling vTaskDelete before queue operations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes