Bird
0
0

What will be the output of the following FreeRTOS task code snippet?

medium📝 Predict Output Q13 of 15
FreeRTOS - Task Creation and Management
What will be the output of the following FreeRTOS task code snippet?
void Task1(void *pvParameters) {
  for (;;) {
    printf("Task1 running\n");
    vTaskDelay(pdMS_TO_TICKS(1000));
  }
}

void Task2(void *pvParameters) {
  for (;;) {
    printf("Task2 running\n");
    vTaskDelay(pdMS_TO_TICKS(500));
  }
}
AOnly Task1 will print because Task2 is blocked.
BBoth tasks print at the same time without delay.
CTask2 will print once, then stop.
DTask1 running every 1 second, Task2 running every 0.5 seconds, both printing alternately.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the delay times in each task

    Task1 delays 1000 ms (1 second) between prints; Task2 delays 500 ms (0.5 seconds).
  2. Step 2: Understand task scheduling

    Both tasks run independently and print their messages at their own intervals, so Task2 prints twice as often as Task1.
  3. Final Answer:

    Task1 running every 1 second, Task2 running every 0.5 seconds, both printing alternately. -> Option D
  4. Quick Check:

    Delays control print frequency = Task1 running every 1 second, Task2 running every 0.5 seconds, both printing alternately. [OK]
Quick Trick: Check vTaskDelay times to predict print frequency [OK]
Common Mistakes:
  • Assuming tasks block each other
  • Thinking Task2 stops after one print
  • Ignoring delays causing print timing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes