Bird
Raised Fist0
FreeRTOSprogramming~10 mins

Why design patterns ensure reliable multi-tasking 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 FreeRTOS task that prints "Hello".

FreeRTOS
xTaskCreate([1], "Task1", 1000, NULL, 1, NULL);
Drag options to blanks, or click blank then click option'
AvTaskStartScheduler
BvTaskFunction
CvTaskDelete
DvTaskDelay
Attempts:
3 left
💡 Hint
Common Mistakes
Using scheduler or delay functions instead of the task function.
2fill in blank
medium

Complete the code to delay a task for 100 ticks.

FreeRTOS
vTaskDelay([1]);
Drag options to blanks, or click blank then click option'
A1000
B10
C100
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using milliseconds instead of ticks.
Using too large or too small values.
3fill in blank
hard

Fix the error in the task creation code to ensure the task runs properly.

FreeRTOS
xTaskCreate(vTaskFunction, "Task2", [1], NULL, 1, NULL);
Drag options to blanks, or click blank then click option'
A100
BNULL
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or NULL for stack size.
Using negative numbers.
4fill in blank
hard

Fill both blanks to create a reliable queue and send data to it.

FreeRTOS
QueueHandle_t queue = xQueueCreate([1], sizeof(int));
xQueueSend(queue, &[2], portMAX_DELAY);
Drag options to blanks, or click blank then click option'
A10
Bdata
C5
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong queue size.
Sending undefined variables.
5fill in blank
hard

Fill all three blanks to receive data from a queue and process it safely.

FreeRTOS
int [1];
if(xQueueReceive(queue, &[2], [3]) == pdPASS) {
    process([1]);
}
Drag options to blanks, or click blank then click option'
AreceivedData
CportMAX_DELAY
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names.
Using zero timeout causing immediate return.

Practice

(1/5)
1. Why do design patterns help ensure reliable multi-tasking in FreeRTOS?
easy
A. They make tasks run faster by skipping synchronization.
B. They organize tasks to safely share resources and avoid conflicts.
C. They allow tasks to ignore priority rules.
D. They remove the need for task communication.

Solution

  1. Step 1: Understand task coordination

    Design patterns help tasks work together by managing how they share resources.
  2. Step 2: Recognize safety and reliability

    By organizing resource access, patterns prevent conflicts and crashes in multi-tasking.
  3. Final Answer:

    They organize tasks to safely share resources and avoid conflicts. -> Option B
  4. Quick Check:

    Safe resource sharing = Reliable multi-tasking [OK]
Hint: Think: patterns keep tasks from stepping on each other [OK]
Common Mistakes:
  • Assuming patterns speed up tasks by skipping safety
  • Believing tasks can ignore priorities safely
  • Thinking communication is unnecessary
2. Which FreeRTOS feature is commonly used in design patterns to protect shared resources?
easy
A. Software timers
B. Task notifications
C. Mutexes
D. Event groups

Solution

  1. Step 1: Identify resource protection tools

    Mutexes are designed to lock resources so only one task uses them at a time.
  2. Step 2: Match with design pattern usage

    Design patterns use mutexes to avoid conflicts when tasks share data or hardware.
  3. Final Answer:

    Mutexes -> Option C
  4. Quick Check:

    Mutex = Resource protection [OK]
Hint: Mutexes lock resources to prevent conflicts [OK]
Common Mistakes:
  • Confusing mutexes with timers or notifications
  • Thinking event groups protect resources
  • Assuming software timers manage resource access
3. Given this FreeRTOS code snippet, what is the expected output?
SemaphoreHandle_t mutex = xSemaphoreCreateMutex();

void Task1(void *pvParameters) {
  if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) {
    printf("Task1 running\n");
    xSemaphoreGive(mutex);
  }
  vTaskDelete(NULL);
}

void Task2(void *pvParameters) {
  if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) {
    printf("Task2 running\n");
    xSemaphoreGive(mutex);
  }
  vTaskDelete(NULL);
}
medium
A. Task1 running or Task2 running, but never both at the same time
B. Task2 running\nTask1 running
C. No output because mutex is never given
D. Task1 running\nTask2 running

Solution

  1. Step 1: Understand mutex behavior in tasks

    Mutex allows only one task to enter the critical section at a time, so tasks run their print statements one after another.
  2. Step 2: Analyze output possibilities

    Either Task1 or Task2 prints first, then the other prints after mutex is released; they never print simultaneously.
  3. Final Answer:

    Task1 running or Task2 running, but never both at the same time -> Option A
  4. Quick Check:

    Mutex serializes output = Task1 running or Task2 running, but never both at the same time [OK]
Hint: Mutex lets only one task print at a time [OK]
Common Mistakes:
  • Assuming both print simultaneously
  • Thinking mutex is never released
  • Expecting fixed order of task execution
4. What is wrong with this FreeRTOS design pattern code snippet?
void TaskA(void *pvParameters) {
  xSemaphoreTake(mutex, 0);
  // critical section code
  xSemaphoreGive(mutex);
  vTaskDelete(NULL);
}
medium
A. Using zero block time may cause task to skip critical section without waiting.
B. Mutex is given before taking it.
C. vTaskDelete should be called before giving mutex.
D. Critical section code is missing.

Solution

  1. Step 1: Analyze semaphore take with zero block time

    Using zero block time means the task tries to take the mutex but does not wait if it's unavailable, possibly skipping the critical section.
  2. Step 2: Understand impact on reliability

    This can cause unreliable behavior because the task may not execute the critical section safely every time.
  3. Final Answer:

    Using zero block time may cause task to skip critical section without waiting. -> Option A
  4. Quick Check:

    Zero wait risks skipping mutex [OK]
Hint: Zero wait means no blocking; task may skip critical section [OK]
Common Mistakes:
  • Thinking mutex is given before taken
  • Believing vTaskDelete order matters here
  • Assuming critical section must be shown
5. You want to design a FreeRTOS system where multiple tasks send data safely to a single processing task without data loss or corruption. Which design pattern best ensures reliable multi-tasking?
hard
A. Use a shared global variable without synchronization.
B. Use multiple mutexes for each task to lock the processor.
C. Use task notifications to broadcast data to all tasks.
D. Use a queue to send data from tasks to the processing task.

Solution

  1. Step 1: Identify safe data transfer method

    Queues in FreeRTOS safely store data from multiple tasks and deliver it to one consumer task without corruption.
  2. Step 2: Compare other options

    Shared variables without sync risk corruption; multiple mutexes locking processor is inefficient; task notifications are for signaling, not data transfer.
  3. Final Answer:

    Use a queue to send data from tasks to the processing task. -> Option D
  4. Quick Check:

    Queue = Safe multi-task data transfer [OK]
Hint: Queues safely pass data between tasks [OK]
Common Mistakes:
  • Using shared variables without locks
  • Misusing mutexes to lock processor
  • Confusing notifications with data queues
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