In FreeRTOS, tasks often need to share data safely. Why are queues the preferred method for this?
Think about how tasks can avoid interfering with each other's data.
Queues in FreeRTOS ensure that data passed between tasks is handled safely and without corruption by managing access and synchronization internally.
Consider two tasks: TaskA sends the number 10 to a queue, and TaskB receives from it. What value does TaskB receive?
QueueHandle_t queue = xQueueCreate(1, sizeof(int)); int valueToSend = 10; xQueueSend(queue, &valueToSend, 0); int receivedValue = 0; xQueueReceive(queue, &receivedValue, 0); printf("%d", receivedValue);
What value was sent to the queue before receiving?
The value 10 was sent to the queue and then received, so the output is 10.
What error will occur when running this code snippet?
QueueHandle_t queue = xQueueCreate(1, sizeof(int)); int value = 5; xQueueReceive(queue, &value, 0);
Think about what happens if you try to receive from an empty queue with zero wait time.
Since the queue is empty and the wait time is zero, xQueueReceive returns immediately with failure, and the value is not updated.
Select the correct code to create a queue that can hold 5 integers.
Remember the order of parameters: number of items, size of each item.
xQueueCreate takes the number of items first, then the size of each item in bytes. Option A is correct.
Explain how using queues for inter-task communication prevents race conditions in FreeRTOS.
Think about how queues control the order of data access between tasks.
Queues act as a safe buffer that serializes data exchange, so tasks do not access shared data simultaneously, preventing race conditions.
