Challenge - 5 Problems
Queue Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output when sending to a full queue?
Consider a FreeRTOS queue with length 2. The queue is already full. What will be the return value of xQueueSend when trying to add another item without waiting?
FreeRTOS
QueueHandle_t queue = xQueueCreate(2, sizeof(int)); int item = 10; int ret1 = xQueueSend(queue, &item, 0); int ret2 = xQueueSend(queue, &item, 0); int ret3 = xQueueSend(queue, &item, 0); // Queue is full here // What is ret3?
Attempts:
2 left
💡 Hint
Check the behavior of xQueueSend with zero block time when the queue is full.
✗ Incorrect
When xQueueSend is called with a block time of 0 and the queue is full, it returns errQUEUE_FULL (0) immediately without blocking.
❓ Predict Output
intermediateWhat happens when receiving from an empty queue with zero wait?
Given a FreeRTOS queue that is empty, what will xQueueReceive return if called with zero block time?
FreeRTOS
QueueHandle_t queue = xQueueCreate(3, sizeof(int)); int receivedValue; int ret = xQueueReceive(queue, &receivedValue, 0); // Queue is empty // What is ret?
Attempts:
2 left
💡 Hint
Think about what happens if you try to receive from an empty queue without waiting.
✗ Incorrect
xQueueReceive returns 0 (errQUEUE_EMPTY) immediately if the queue is empty and block time is zero.
🧠 Conceptual
advancedWhich FreeRTOS API call blocks until space is available in a full queue?
You want to send data to a queue that might be full. Which xQueueSend variant will block until there is space to add the item?
Attempts:
2 left
💡 Hint
Consider how block time affects waiting behavior in FreeRTOS queue functions.
✗ Incorrect
Setting block time to portMAX_DELAY causes xQueueSend to block indefinitely until space is available.
❓ Predict Output
advancedWhat is the output of this code snippet handling queue empty condition?
Analyze the following FreeRTOS code snippet. What will be printed?
FreeRTOS
QueueHandle_t queue = xQueueCreate(1, sizeof(int)); int val = 42; xQueueSend(queue, &val, 0); int received = 0; if(xQueueReceive(queue, &received, 0) == pdPASS) { printf("Received: %d\n", received); } if(xQueueReceive(queue, &received, 0) == pdPASS) { printf("Received again: %d\n", received); } else { printf("Queue empty\n"); }
Attempts:
2 left
💡 Hint
Remember that the queue has only one item and the second receive tries to get from empty queue.
✗ Incorrect
The first receive gets the value 42 and prints it. The second receive fails because the queue is empty and prints "Queue empty".
🔧 Debug
expertWhy does this FreeRTOS queue send block indefinitely?
Given the code below, why does the task block forever on xQueueSend?
FreeRTOS
QueueHandle_t queue = xQueueCreate(1, sizeof(int)); int data = 5; // Task A xQueueSend(queue, &data, portMAX_DELAY); // Task B int received; xQueueReceive(queue, &received, 0); // Task A tries to send again xQueueSend(queue, &data, portMAX_DELAY); // Blocks here
Attempts:
2 left
💡 Hint
Think about task scheduling and whether Task B runs before Task A tries to send again.
✗ Incorrect
If Task B does not run to remove the item, the queue remains full. Task A blocks indefinitely waiting for space.
