Not all tasks are equal
In priority scheduling every task carries a priority number. When several tasks are runnable, the scheduler always picks the highest priority one. This lets urgent work, like handling input, run ahead of background work, like cleanup.
How it usually works
- Tasks are grouped by priority level, often as one queue per level.
- The scheduler serves the highest non empty queue first.
- Within a level, tasks are typically run in round robin so equals share time.
The starvation trap
If high priority tasks keep arriving, a low priority task may never run. This is starvation. A classic fix is aging: the scheduler slowly raises the priority of a task that has waited a long time, so eventually it climbs high enough to run.
Priority inversion
A subtler problem is priority inversion, where a high priority task waits on a lock held by a low priority task that a medium task keeps preempting. Priority inheritance, temporarily boosting the lock holder, breaks this deadlock.
Key idea
Priority scheduling runs the most important runnable task first, but needs aging to prevent starvation of low priority tasks and priority inheritance to avoid inversion on shared locks.