0
0
FreeRTOSprogramming~20 mins

Why priority design matters in FreeRTOS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Priority Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this FreeRTOS task priority example?

Consider two tasks in FreeRTOS: TaskA with priority 2 and TaskB with priority 1. Both print a message in an infinite loop with a delay. What will be the order of printed messages?

FreeRTOS
void TaskA(void *pvParameters) {
    for (;;) {
        printf("TaskA running\n");
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

void TaskB(void *pvParameters) {
    for (;;) {
        printf("TaskB running\n");
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

int main() {
    xTaskCreate(TaskA, "TaskA", 1000, NULL, 2, NULL);
    xTaskCreate(TaskB, "TaskB", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
ATaskA running\nTaskB running\nTaskA running\nTaskB running\n... alternating
BTaskB running\nTaskA running\nTaskB running\nTaskA running\n... alternating
CTaskA running\nTaskA running\nTaskA running\n... TaskB never runs
DTaskB running\nTaskB running\nTaskB running\n... TaskA never runs
Attempts:
2 left
💡 Hint

Remember that FreeRTOS always runs the highest priority task that is ready.

🧠 Conceptual
intermediate
1:30remaining
Why is priority inversion a problem in FreeRTOS?

In FreeRTOS, what problem occurs when a low priority task holds a resource needed by a high priority task, but a medium priority task preempts the low priority task?

APriority inversion causes the high priority task to be blocked longer than expected.
BThe low priority task immediately releases the resource, so no problem occurs.
CThe medium priority task inherits the high priority automatically.
DThe scheduler disables all tasks until the resource is free.
Attempts:
2 left
💡 Hint

Think about what happens when a medium priority task runs instead of the low priority task holding the resource.

🔧 Debug
advanced
2:00remaining
Identify the cause of starvation in this FreeRTOS priority setup

Given three tasks with priorities 3, 2, and 1, the lowest priority task never seems to run. What is the most likely cause?

FreeRTOS
xTaskCreate(TaskHigh, "High", 1000, NULL, 3, NULL);
xTaskCreate(TaskMedium, "Medium", 1000, NULL, 2, NULL);
xTaskCreate(TaskLow, "Low", 1000, NULL, 1, NULL);

// All tasks run infinite loops without blocking or delaying
AThe medium priority task has higher priority than the high priority task.
BThe scheduler has a bug and ignores the low priority task.
CThe low priority task has a syntax error and never starts.
DThe low priority task is starved because higher priority tasks never block or delay.
Attempts:
2 left
💡 Hint

Consider how FreeRTOS schedules tasks based on priority and task states.

📝 Syntax
advanced
1:00remaining
Which FreeRTOS API call correctly sets task priority?

Which of the following calls correctly changes the priority of a task handle xTaskHandle to 5?

AxTaskSetPriority(xTaskHandle, 5);
BvTaskPrioritySet(xTaskHandle, 5);
CvTaskSetPriority(5, xTaskHandle);
DvTaskPriorityChange(xTaskHandle, 5);
Attempts:
2 left
💡 Hint

Check the FreeRTOS API naming conventions for setting task priority.

🚀 Application
expert
3:00remaining
How to prevent priority inversion using FreeRTOS features?

You have a high priority task and a low priority task sharing a mutex. A medium priority task often preempts the low priority task, causing priority inversion. Which FreeRTOS feature can you use to prevent this?

AUse a binary semaphore instead of a mutex.
BIncrease the medium priority task priority above the high priority task.
CUse priority inheritance protocol by creating the mutex with <code>xSemaphoreCreateMutex()</code>.
DDisable the scheduler while the low priority task holds the mutex.
Attempts:
2 left
💡 Hint

Think about how FreeRTOS mutexes handle priority inheritance.