Page 362 - DCAP103_Principle of operating system
P. 362

Unit 12: Processes and Threads in Windows



                                                                                                  Notes
                        Figure 12.5: Windows 2000 Supports 32 Priorities for Threads


































            Over the course of time, some patches were made to the basic scheduling algorithm to improve
            system performance. Under certain specific conditions, the current priority of a user thread can
            be raised above the base priority (by the operating system), but never above priority 15. Since
            the array of Figure 12.5 is based on the current priority, changing this priority affects scheduling.
            No adjustments are ever made to threads running at priority 15 or higher.

            Let us now see when a thread’s priority is raised. First, when an I/O operation completes and
            releases a waiting thread, the priority is boosted to give it a chance to run again quickly and start
            more I/O. The idea here is to keep the I/O devices busy. The amount of boost depends on the
            I/O device, typically 1 for a disk, 2 for a serial line, 6 for the keyboard, and 8 for the sound card.
            Second, if a thread was waiting on a semaphore, mutex, or other event, when it is released, it
            gets boosted by 2 units if it is in the foreground process (the process controlling the window to
            which keyboard input is sent) and 1 unit otherwise. This fix tends to raise interactive processes
            above the big crowd at level 8. Finally, if a GUI thread wakes up because window input is now
            available, it gets a boost for the same reason.
            These boosts are not forever. They take effect immediately, but if a thread uses all of its next
            quantum, it loses one point and moves down one queue in the priority array. If it uses up another
            full quantum, it moves down to another level, and so on until it hits its base level, where it remains
            until it is boosted again. Clearly, if a thread wants good service, it should play a lot of music.
            There is an other case in which the system fiddles with the priorities. Imagine that two threads
            are working together on a producer-consumer type problem. The producer’s work is harder, so
            it gets a high priority, say 12, compared to the consumer’s 4. At a certain point, the producer
            has filled up a shared buffer and blocks on a semaphore, as illustrated in Figure 12.6 (a).








                                             LOVELY PROFESSIONAL UNIVERSITY                                   355
   357   358   359   360   361   362   363   364   365   366   367