Thread Starvation

If a thread's priority remains low for too long, it can be starved for processor time. The time slicer includes an algorithm that prevents thread starvation by temporarily boosting threads that have not been scheduled within a reasonable amount of time. Reasonable is defined as a number of milliseconds calculated by multiplying the size of the time-slice quantum by the number of executable threads, then multiplying the result by an internal threshold value.

The system cannot dynamically change the priority of a thread that belongs to the real-time priority class. Real-time threads are excluded from the thread starvation algorithm; moreover, real-time threads can starve threads of other priority classes in spite of the starvation algorithm.

An idle thread is one that runs only when there are no higher priority threads to run. All priorities in the idle priority class except the system reserved 0 priority are included in the thread starvation algorithm.

Idle, normal, and high priority class threads are normally not starved. Within these priority classes, the system dynamically boosts the priorities of starving threads using time decayed boost functions. During every starvation detection interval (which varies depending on the number of runnable threads) the system recalculates the dynamic priorities of all idle, normal, and high priority threads based on the recent processor usage. When the system finds a thread that has not run for an extended period, the system gives it a timed decayed boost to the highest priority possible for threads of the normal priority class. By adjusting both the period of time between checks and the acceptable starvation level of threads, the system prevents starvation while efficiently setting the priorities of threads.