Consider three FreeRTOS tasks with priorities 2, 3, and 1 respectively. Each task prints its name once when it runs. What is the order of printed task names?
void Task1(void *pvParameters) {
printf("Task1\n");
vTaskDelete(NULL);
}
void Task2(void *pvParameters) {
printf("Task2\n");
vTaskDelete(NULL);
}
void Task3(void *pvParameters) {
printf("Task3\n");
vTaskDelete(NULL);
}
int main() {
xTaskCreate(Task1, "Task1", 1000, NULL, 2, NULL);
xTaskCreate(Task2, "Task2", 1000, NULL, 3, NULL);
xTaskCreate(Task3, "Task3", 1000, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}Remember, FreeRTOS runs the highest priority task that is ready.
Task2 has the highest priority (3), so it runs first. Then Task1 (priority 2), then Task3 (priority 1).
Two FreeRTOS tasks have the same priority and both are ready to run. Each prints its name once. What is the possible output order?
void TaskA(void *pvParameters) {
printf("TaskA\n");
vTaskDelete(NULL);
}
void TaskB(void *pvParameters) {
printf("TaskB\n");
vTaskDelete(NULL);
}
int main() {
xTaskCreate(TaskA, "TaskA", 1000, NULL, 2, NULL);
xTaskCreate(TaskB, "TaskB", 1000, NULL, 2, NULL);
vTaskStartScheduler();
return 0;
}Tasks with the same priority are scheduled round-robin.
When tasks have the same priority, FreeRTOS time-slices between them, so either task can run first.
Given three tasks with priorities 3 (high), 2 (medium), and 1 (low). The low priority task holds a mutex needed by the high priority task. The medium priority task runs continuously. What problem occurs and why?
/*
TaskLow (priority 1) locks mutex and starts long processing
TaskHigh (priority 3) tries to lock mutex and blocks
TaskMedium (priority 2) runs continuously
*/Think about how medium priority tasks affect low priority tasks holding resources needed by high priority tasks.
Priority inversion happens because the medium priority task keeps running, preventing the low priority task from releasing the mutex needed by the high priority task.
Which option contains the correct syntax to create a FreeRTOS task with priority 4?
Check the parameter types and count for xTaskCreate.
Option A uses correct string for task name and integer for priority with all required parameters.
In a FreeRTOS system, three tasks with priorities 3, 2, and 1 are ready. The highest priority task runs for 5 ticks, then blocks. The next highest runs for 3 ticks, then blocks. The lowest priority task runs for 4 ticks. How many context switches occur in total?
Count switches when tasks block and scheduler switches to next ready task.
Initially, highest priority runs (no switch). When it blocks, switch to medium priority (1). When medium blocks, switch to low priority (2). When low finishes, no more tasks, so total 2 switches. But starting scheduler counts as first switch (0 to highest), total 3. Also, when tasks delete themselves, scheduler switches back to idle task (3). Total 4 context switches.