Consider the following FreeRTOS code snippet that creates two tasks with different priorities. What will be the output printed by the tasks?
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> void Task1(void *pvParameters) { printf("Task1 running with priority %lu\n", (unsigned long)uxTaskPriorityGet(NULL)); vTaskDelete(NULL); } void Task2(void *pvParameters) { printf("Task2 running with priority %lu\n", (unsigned long)uxTaskPriorityGet(NULL)); vTaskDelete(NULL); } int main(void) { xTaskCreate(Task1, "Task1", 1000, NULL, 2, NULL); xTaskCreate(Task2, "Task2", 1000, NULL, 3, NULL); vTaskStartScheduler(); return 0; }
Remember that FreeRTOS runs the highest priority task that is ready first.
Task2 has priority 3, which is higher than Task1's priority 2. So Task2 runs first and prints its priority, then Task1 runs.
In FreeRTOS, which function is used to change the priority of a task that is already running?
Look for the function that explicitly mentions setting priority.
vTaskPrioritySet changes the priority of a specified task at runtime.
Examine the code below. Why does Task1 never get to run?
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> void Task1(void *pvParameters) { while(1) { printf("Task1 running\n"); vTaskDelay(pdMS_TO_TICKS(100)); } } void Task2(void *pvParameters) { while(1) { printf("Task2 running\n"); } } int main(void) { xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL); xTaskCreate(Task2, "Task2", 1000, NULL, 2, NULL); vTaskStartScheduler(); return 0; }
Think about task priorities and blocking behavior.
Task2 has priority 2 and never blocks, so it always runs. Task1 with priority 1 never gets CPU time.
Which option contains the correct syntax to create a task with priority 5?
Check the parameter types and count.
Option B uses correct string for task name, numeric priority, and correct number of parameters.
You have two tasks: TaskA with priority 3 and TaskB with priority 5. TaskB runs continuously and causes TaskA starvation. Which approach correctly changes TaskB's priority dynamically to allow TaskA to run?
Think about temporarily lowering the running task's priority.
Lowering TaskB's priority temporarily allows TaskA to run without stopping TaskB permanently.