Bird
0
0

Given this FreeRTOS code snippet, what will be the output sequence printed?

medium📝 Predict Output Q13 of 15
FreeRTOS - RTOS Fundamentals
Given this FreeRTOS code snippet, what will be the output sequence printed?
void Task1(void *pvParameters) {
  for (int i = 0; i < 3; i++) {
    printf("Task1: %d\n", i);
    vTaskDelay(10);
  }
  vTaskDelete(NULL);
}

void Task2(void *pvParameters) {
  for (int i = 0; i < 3; i++) {
    printf("Task2: %d\n", i);
    vTaskDelay(10);
  }
  vTaskDelete(NULL);
}
ATask1: 0 Task1: 1 Task1: 2 Task2: 0 Task2: 1 Task2: 2
BTask2: 0 Task2: 1 Task2: 2 Task1: 0 Task1: 1 Task1: 2
CTask1: 0 Task2: 1 Task1: 2 Task2: 0 Task1: 1 Task2: 2
DTask1: 0 Task2: 0 Task1: 1 Task2: 1 Task1: 2 Task2: 2
Step-by-Step Solution
Solution:
  1. Step 1: Understand vTaskDelay effect

    vTaskDelay causes the current task to pause, allowing other tasks of equal priority to run.
  2. Step 2: Trace task execution order

    Task1 prints 0, delays; Task2 runs, prints 0, delays; then Task1 prints 1, and so on, alternating output.
  3. Final Answer:

    Task1: 0 Task2: 0 Task1: 1 Task2: 1 Task1: 2 Task2: 2 -> Option D
  4. Quick Check:

    vTaskDelay causes task switching, so output alternates [OK]
Quick Trick: vTaskDelay switches tasks, output alternates between tasks [OK]
Common Mistakes:
  • Assuming one task runs fully before the other
  • Ignoring vTaskDelay effect
  • Mixing output order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes