Bird
Raised Fist0
FreeRTOSprogramming~10 mins

Why queues are needed for inter-task communication in FreeRTOS - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a queue that can hold 5 integers.

FreeRTOS
QueueHandle_t xQueue = xQueueCreate([1], sizeof(int));
Drag options to blanks, or click blank then click option'
A5
B10
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 which creates too small a queue.
Using 10 which is more than needed.
2fill in blank
medium

Complete the code to send data to the queue from a task.

FreeRTOS
int data = 100;
xQueueSend([1], &data, portMAX_DELAY);
Drag options to blanks, or click blank then click option'
AxTaskHandle
BxQueue
CNULL
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Passing NULL or task handle instead of queue handle.
Passing data variable instead of queue handle.
3fill in blank
hard

Fix the error in the code to receive data from the queue.

FreeRTOS
int receivedValue;
if(xQueueReceive([1], &receivedValue, 0) == pdPASS) {
    // Process receivedValue
}
Drag options to blanks, or click blank then click option'
ANULL
B&receivedValue
CxQueue
DxTaskHandle
Attempts:
3 left
💡 Hint
Common Mistakes
Using task handle or NULL instead of queue handle.
Passing address of receivedValue instead of queue handle.
4fill in blank
hard

Fill both blanks to create a queue and send data safely.

FreeRTOS
QueueHandle_t [1] = xQueueCreate(3, sizeof(int));
int value = 42;
xQueueSend([2], &value, 0);
Drag options to blanks, or click blank then click option'
AmyQueue
BxQueue
Cvalue
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for creation and sending.
Using NULL or value instead of queue handle.
5fill in blank
hard

Fill all three blanks to receive data and check the result.

FreeRTOS
int dataReceived;
if(xQueueReceive([1], &[2], [3]) == pdPASS) {
    // Use dataReceived
}
Drag options to blanks, or click blank then click option'
AxQueue
BdataReceived
CportMAX_DELAY
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Using 0 instead of portMAX_DELAY causing no wait.

Practice

(1/5)
1. Why are queues needed for inter-task communication in FreeRTOS?
easy
A. To create multiple copies of the same task
B. To speed up the execution of a single task
C. To store data permanently on disk
D. To safely send and receive data between tasks without conflicts

Solution

  1. Step 1: Understand the role of queues in task communication

    Queues allow tasks to exchange data safely without overwriting or losing information.
  2. Step 2: Identify the main purpose of queues in FreeRTOS

    They prevent conflicts by managing data flow between tasks running at different speeds.
  3. Final Answer:

    To safely send and receive data between tasks without conflicts -> Option D
  4. Quick Check:

    Queues ensure safe data exchange = A [OK]
Hint: Queues prevent data conflicts between tasks [OK]
Common Mistakes:
  • Thinking queues speed up single tasks
  • Confusing queues with permanent storage
  • Believing queues duplicate tasks
2. Which of the following is the correct way to create a queue in FreeRTOS?
easy
A. xQueueCreate(10, sizeof(int));
B. xQueueStart(10, sizeof(int));
C. createQueue(10, sizeof(int));
D. QueueCreate(10, sizeof(int));

Solution

  1. Step 1: Recall the FreeRTOS queue creation function

    The correct function to create a queue is xQueueCreate.
  2. Step 2: Verify the syntax of the function call

    The function takes two parameters: the number of items and the size of each item.
  3. Final Answer:

    xQueueCreate(10, sizeof(int)); -> Option A
  4. Quick Check:

    Queue creation uses xQueueCreate() = A [OK]
Hint: Remember FreeRTOS queue creation is xQueueCreate() [OK]
Common Mistakes:
  • Using incorrect function names like xQueueStart
  • Mixing up function name capitalization
  • Omitting parameters or using wrong ones
3. Given the following code snippet, what will be the output?
QueueHandle_t queue = xQueueCreate(2, sizeof(int));
int value = 5;
xQueueSend(queue, &value, 0);
value = 10;
xQueueSend(queue, &value, 0);
int received;
xQueueReceive(queue, &received, 0);
printf("%d", received);
medium
A. 10
B. 5
C. 0
D. Compilation error

Solution

  1. Step 1: Understand queue send order

    The first value sent is 5, then 10. Queues keep order FIFO (first in, first out).
  2. Step 2: Check which value is received first

    The first received value is 5, the first sent value.
  3. Final Answer:

    5 -> Option B
  4. Quick Check:

    Queue FIFO order means first sent is first received = C [OK]
Hint: Queues deliver data in FIFO order [OK]
Common Mistakes:
  • Assuming last sent value is received first
  • Confusing queue with stack behavior
  • Expecting zero instead of actual data
4. What is wrong with this code snippet for sending data to a queue?
QueueHandle_t queue = xQueueCreate(1, sizeof(int));
int value = 42;
xQueueSend(queue, &value, 0);
xQueueSend(queue, &value, 0);
medium
A. Queue must be created with zero size
B. The data type int is not allowed in queues
C. The queue size is too small for two sends without receiving
D. xQueueSend requires a pointer to a pointer

Solution

  1. Step 1: Analyze queue size and send operations

    The queue can hold only 1 item, but two sends are done without receiving.
  2. Step 2: Identify the problem caused by queue overflow

    The second send will fail or block because the queue is full.
  3. Final Answer:

    The queue size is too small for two sends without receiving -> Option C
  4. Quick Check:

    Queue size limits sends = D [OK]
Hint: Queue size limits how many items can be sent before receive [OK]
Common Mistakes:
  • Thinking int is invalid data type for queues
  • Misunderstanding xQueueSend parameters
  • Believing queue size can be zero
5. You have two tasks: Task A produces sensor data at irregular intervals, and Task B processes this data. Why is using a queue the best method for communication between these tasks?
hard
A. Because queues buffer data safely and handle different task speeds
B. Because queues force both tasks to run at the same speed
C. Because queues automatically delete old data when full
D. Because queues allow tasks to share variables directly without copying

Solution

  1. Step 1: Understand task speed differences

    Task A produces data irregularly, Task B processes it at its own pace.
  2. Step 2: Identify queue benefits for this scenario

    Queues buffer data safely and keep order, allowing tasks to work independently without data loss.
  3. Step 3: Eliminate incorrect options

    Queues do not force speed matching, do not delete data automatically, and do not share variables directly.
  4. Final Answer:

    Because queues buffer data safely and handle different task speeds -> Option A
  5. Quick Check:

    Queues buffer and sync tasks = B [OK]
Hint: Queues handle different task speeds by buffering data [OK]
Common Mistakes:
  • Thinking queues force tasks to run at same speed
  • Believing queues delete old data automatically
  • Confusing queues with shared variable access
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard