0
0
FreeRTOSprogramming~10 mins

Task starvation and priority inversion in FreeRTOS - Interactive Code Practice

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

Complete the code to create a task with the highest priority.

FreeRTOS
xTaskCreate(taskFunction, "Task1", 1000, NULL, [1], NULL);
Drag options to blanks, or click blank then click option'
A0
B1
C5
DconfigMAX_PRIORITIES - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as highest priority (0 is the lowest).
Using a priority higher than configMAX_PRIORITIES - 1.
2fill in blank
medium

Complete the code to take a mutex to avoid priority inversion.

FreeRTOS
xSemaphoreTake([1], portMAX_DELAY);
Drag options to blanks, or click blank then click option'
AxQueue
BxTaskHandle
CxMutex
DxTimer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a queue handle instead of a mutex.
Using a timer handle instead of a mutex.
3fill in blank
hard

Fix the error in the code to prevent task starvation by yielding the processor.

FreeRTOS
void vTaskFunction(void *pvParameters) {
    for(;;) {
        // Task code
        [1]();
    }
}
Drag options to blanks, or click blank then click option'
AtaskYIELD
BvTaskSuspend
CvTaskDelay
DxSemaphoreGive
Attempts:
3 left
💡 Hint
Common Mistakes
Using vTaskDelay without a delay time.
Suspending the task instead of yielding.
4fill in blank
hard

Fill both blanks to create a priority inheritance mutex and take it.

FreeRTOS
xMutex = xSemaphoreCreate[1]();
if(xSemaphoreTake(xMutex, [2]) == pdTRUE) {
    // Access resource
}
Drag options to blanks, or click blank then click option'
AMutex
BBinary
CportMAX_DELAY
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using binary semaphore instead of mutex for priority inheritance.
Using 0 as wait time which causes immediate failure if mutex is not available.
5fill in blank
hard

Fill all three blanks to create a task that avoids starvation by delaying and yielding.

FreeRTOS
void vTaskFunction(void *pvParameters) {
    for(;;) {
        // Do work
        vTaskDelay([1]);
        [2]();
        vTaskDelay([3]);
    }
}
Drag options to blanks, or click blank then click option'
ApdMS_TO_TICKS(10)
BtaskYIELD
CpdMS_TO_TICKS(5)
DvTaskSuspend
Attempts:
3 left
💡 Hint
Common Mistakes
Using vTaskSuspend() which stops the task indefinitely.
Not yielding between delays.