The rule is: always run the highest-priority task that is currently Ready, and preempt immediately when a higher-priority task becomes Ready. So at any moment the core is running the most urgent ready work; lower-priority tasks only run when no higher-priority task is ready (i.e., the higher ones are blocked or suspended). The scheduler gets the opportunity to make this decision at three kinds of moments: on every tick interrupt (the periodic kernel heartbeat, which also handles time-slicing among equal-priority tasks and expiring delays); whenever the running task blocks, since the kernel must then pick someone else; and whenever an event makes a higher-priority task Ready, for example an ISR gives a semaphore that a high-priority task was waiting on, triggering a context switch on ISR exit. That event-driven part matters: context switches aren't only on the tick, they happen the instant a higher-priority task becomes runnable, which is what gives a preemptive RTOS its responsiveness. If two tasks share the top ready priority, the scheduler time-slices between them on ticks (round-robin), covered next lesson.
RTOS & Real-Time Concepts · Interview question
How does a priority-based preemptive scheduler decide what runs?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Tasks & the Scheduler
A task is a function with its own stack, priority, and state; the scheduler runs the highest-priority ready task. The task lifecycle (Ready/Running/Blocked), the idle task, and vTaskDelay.