Complete the code to create a task with the highest priority.
xTaskCreate(taskFunction, "Task1", 1000, NULL, [1], NULL);
The highest priority in FreeRTOS is configMAX_PRIORITIES - 1 because priorities start at 0.
Complete the code to take a mutex to avoid priority inversion.
xSemaphoreTake([1], portMAX_DELAY);Mutexes are used to avoid priority inversion by controlling access to shared resources.
Fix the error in the code to prevent task starvation by yielding the processor.
void vTaskFunction(void *pvParameters) {
for(;;) {
// Task code
[1]();
}
}Calling taskYIELD() allows other tasks of the same priority to run, preventing starvation.
Fill both blanks to create a priority inheritance mutex and take it.
xMutex = xSemaphoreCreate[1](); if(xSemaphoreTake(xMutex, [2]) == pdTRUE) { // Access resource }
Creating a mutex with xSemaphoreCreateMutex() enables priority inheritance. Using portMAX_DELAY waits indefinitely to take the mutex.
Fill all three blanks to create a task that avoids starvation by delaying and yielding.
void vTaskFunction(void *pvParameters) {
for(;;) {
// Do work
vTaskDelay([1]);
[2]();
vTaskDelay([3]);
}
}vTaskSuspend() which stops the task indefinitely.Delaying the task with vTaskDelay() and yielding with taskYIELD() helps prevent starvation by allowing other tasks to run.