The Windows XP scheduler schedules threads using a priority, preemptive algorithm. It ensures that the highest priority thread will always run. A thread selected to run by the scheduler will continue to run until it is preempted by a higher-priority thread, until it terminates, until its time quantum ends, or until a blocking system call causes the thread to wait (such as on I/O).
Similar to Solaris, priorities are divided into two classes. The variable class contains threads having priorities from 1 to 15, and the real-time class contains threads ranging from 16 to 31. (The thread running at priority 0 is a special thread used for memory management.) The scheduler uses a queue for each scheduling priority and traverses the queues from highest to lowest until it finds a thread that is ready to run. If no ready thread can be found, the scheduler will execute a special thread called the idle thread.
The Win32 API provides several priority classes, which include (together with their base priority values):
- REALTIME_PRIORITY = 24
- HIGH_PRIORITY = 13
- ABOVE_NORMAL_PRIORITY = 10
- NORMAL_PRIORITY = 8
- BELOW_NORMAL_PRIORITY = 6
- IDLE_PRIORITY = 4
Priorities in all classes except the REALTIME_PRIORITY class are variable. Within each of the priority classes is a relative priority, that is based on a similar priority segregation - TIME_CRITICAL, HIGHEST, ABOVE_NORMAL, NORMAL, BELOW_NORMAL, LOWEST, IDLE.
Thus, the global priority of each thread is based on its priority class, and also its relative priority within that class.
When a thread exhausts its time quanta, it is interrupted. If the thread is in a variable-priority class, its priority is lowered, although a priority is never lowered below its base priority value. When a thread is released from a wait operation, the scheduler boosts its priority. The amount of boost depends on what the thread was waiting for. A thread waiting for keyboard input would get a large boost, whereas a thread waiting for a disk operation would get a lower boost. This strategy gives good response times to interactive threads, and also enables the I/O-bound threads to keep the I/O devices busy. This strategy is used by several operating systems, including UNIX. In addition, the windows which the user is currently interacting with receives a priority boost to enhance its response time.