Bird
Raised Fist0
FreeRTOSprogramming~5 mins

Preemptive scheduling behavior in FreeRTOS - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is preemptive scheduling in FreeRTOS?
Preemptive scheduling means the system can stop a running task to start a higher priority task immediately.
Click to reveal answer
beginner
How does FreeRTOS decide which task to run next in preemptive scheduling?
FreeRTOS always runs the highest priority task that is ready to run. If a higher priority task becomes ready, it preempts the current task.
Click to reveal answer
intermediate
What happens if two tasks have the same priority in FreeRTOS preemptive scheduling?
FreeRTOS uses time slicing to share CPU time between tasks of the same priority, switching between them regularly.
Click to reveal answer
intermediate
Why is preemptive scheduling useful in real-time systems?
It ensures important tasks run immediately when needed, improving system responsiveness and meeting timing requirements.
Click to reveal answer
intermediate
What role does the tick interrupt play in FreeRTOS preemptive scheduling?
The tick interrupt triggers the scheduler regularly to check if a higher priority task is ready and switch tasks if needed.
Click to reveal answer
In FreeRTOS preemptive scheduling, what happens when a higher priority task becomes ready?
AThe current task continues until it finishes
BThe scheduler immediately switches to the higher priority task
CThe higher priority task waits until the current task yields
DThe system crashes
What mechanism allows FreeRTOS to switch tasks regularly among same priority tasks?
ATime slicing
BTask suspension
CInterrupt nesting
DPriority inversion
Which component triggers the FreeRTOS scheduler to run periodically?
AIdle task
BWatchdog timer
CTick interrupt
DMemory manager
Why is preemptive scheduling important in real-time applications?
AIt reduces power consumption
BIt simplifies programming
CIt avoids task switching
DIt ensures critical tasks run on time
If a low priority task is running and a higher priority task becomes ready, what does FreeRTOS do?
ASwitches immediately to the higher priority task
BWaits for the low priority task to finish
CRuns both tasks simultaneously
DDisables the higher priority task
Explain how FreeRTOS preemptive scheduling manages tasks with different priorities.
Think about what happens when a more important task needs the CPU.
You got /3 concepts.
    Describe the role of the tick interrupt in FreeRTOS preemptive scheduling.
    Consider how the system knows when to switch tasks.
    You got /4 concepts.

      Practice

      (1/5)
      1. What happens in FreeRTOS when a higher priority task becomes ready while a lower priority task is running under preemptive scheduling?
      easy
      A. The scheduler ignores the higher priority task until the lower priority task yields.
      B. The lower priority task continues running until it finishes.
      C. Both tasks run at the same time.
      D. The higher priority task immediately preempts the lower priority task and starts running.

      Solution

      1. Step 1: Understand preemptive scheduling behavior

        In preemptive scheduling, the system always runs the highest priority task that is ready.
      2. Step 2: Apply to the scenario

        When a higher priority task becomes ready, it interrupts the lower priority task immediately.
      3. Final Answer:

        The higher priority task immediately preempts the lower priority task and starts running. -> Option D
      4. Quick Check:

        Preemptive scheduling = immediate switch to higher priority task [OK]
      Hint: Higher priority tasks always interrupt lower ones immediately [OK]
      Common Mistakes:
      • Thinking tasks run simultaneously on a single core
      • Believing lower priority tasks finish before switching
      • Confusing preemptive with cooperative scheduling
      2. Which of the following is the correct way to enable preemptive scheduling in FreeRTOS configuration?
      easy
      A. #define configUSE_PREEMPTION 1
      B. #define configENABLE_PREEMPTION true
      C. #define configPREEMPTIVE_SCHEDULING 1
      D. #define configUSE_PREEMPTION 0

      Solution

      1. Step 1: Recall FreeRTOS config option for preemption

        The correct macro to enable preemption is configUSE_PREEMPTION.
      2. Step 2: Identify correct value to enable preemption

        Setting configUSE_PREEMPTION to 1 enables preemptive scheduling.
      3. Final Answer:

        #define configUSE_PREEMPTION 1 -> Option A
      4. Quick Check:

        configUSE_PREEMPTION = 1 enables preemption [OK]
      Hint: Enable preemption by setting configUSE_PREEMPTION to 1 [OK]
      Common Mistakes:
      • Using 0 instead of 1 to enable preemption
      • Using wrong macro names
      • Using boolean true instead of 1
      3. Consider two tasks in FreeRTOS: TaskA with priority 2 and TaskB with priority 3. TaskA is running when TaskB becomes ready. What will be the output if both tasks print their names when running?
      medium
      A. TaskA prints first, then TaskB prints after TaskA finishes.
      B. TaskB prints immediately, preempting TaskA.
      C. Both tasks print simultaneously.
      D. No output because tasks block each other.

      Solution

      1. Step 1: Identify task priorities and running state

        TaskA has priority 2 and is running; TaskB has higher priority 3 and becomes ready.
      2. Step 2: Apply preemptive scheduling rules

        TaskB will preempt TaskA immediately and run first, printing its name.
      3. Final Answer:

        TaskB prints immediately, preempting TaskA. -> Option B
      4. Quick Check:

        Higher priority task runs first = TaskB prints first [OK]
      Hint: Higher priority task prints first by preempting lower priority [OK]
      Common Mistakes:
      • Assuming lower priority task finishes before switching
      • Thinking tasks run at the same time
      • Ignoring task priorities
      4. Given this FreeRTOS snippet, what is the error that prevents preemptive scheduling from working?
      #define configUSE_PREEMPTION 0
      
      void Task1(void *pvParameters) {
        while(1) {
          // Task code
        }
      }
      
      void Task2(void *pvParameters) {
        while(1) {
          // Task code
        }
      }
      medium
      A. configUSE_PREEMPTION is set to 0, disabling preemption.
      B. Tasks are missing priority assignments.
      C. Task functions must return int, not void.
      D. Tasks need to call vTaskDelay to allow switching.

      Solution

      1. Step 1: Check configUSE_PREEMPTION value

        The macro is set to 0, which disables preemptive scheduling.
      2. Step 2: Understand effect on scheduling

        With preemption disabled, tasks will not be interrupted automatically by higher priority tasks.
      3. Final Answer:

        configUSE_PREEMPTION is set to 0, disabling preemption. -> Option A
      4. Quick Check:

        configUSE_PREEMPTION = 0 disables preemption [OK]
      Hint: Preemption disabled if configUSE_PREEMPTION = 0 [OK]
      Common Mistakes:
      • Thinking tasks must return int
      • Assuming missing priorities cause preemption failure
      • Believing vTaskDelay is required for preemption
      5. You have three tasks: TaskX (priority 2), TaskY (priority 3), and TaskZ (priority 3). TaskX is running, then both TaskY and TaskZ become ready at the same time. Which task will FreeRTOS run first under preemptive scheduling, and why?
      hard
      A. TaskY runs first because it was created before TaskZ.
      B. TaskZ runs first because it has the same priority as TaskY but higher than TaskX.
      C. Either TaskY or TaskZ runs first; FreeRTOS uses time slicing between equal priorities.
      D. TaskX continues running until it yields.

      Solution

      1. Step 1: Identify task priorities and ready state

        TaskX priority 2 is running; TaskY and TaskZ both have priority 3 and become ready simultaneously.
      2. Step 2: Understand FreeRTOS behavior with equal priority tasks

        FreeRTOS uses time slicing (round-robin) between tasks of equal highest priority.
      3. Step 3: Determine which task runs first

        Either TaskY or TaskZ can run first; the scheduler switches between them fairly.
      4. Final Answer:

        Either TaskY or TaskZ runs first; FreeRTOS uses time slicing between equal priorities. -> Option C
      5. Quick Check:

        Equal priority tasks share CPU time via time slicing [OK]
      Hint: Equal priority tasks share CPU time by time slicing [OK]
      Common Mistakes:
      • Assuming creation order decides first run
      • Thinking lower priority task continues running
      • Believing one equal priority task always runs first
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard