Windows XP Thread scheduling policy

Source: Internet
Author: User
Tags reset thread

Windows XP Thread scheduling policy

Windows 2000/XP Priority-driven multitasking based on thread implementation, and the thread scheduling strategy is different in single-processor and multiprocessor systems. The following describes the thread scheduling policy in a single-processor system. In a single processor system, the processor switching has the following children.

1. Active switching

A thread may voluntarily discard the use of the processor because it is in a waiting state, and Windows 2000/XP will select Tochinami a new thread to start running. Many WIN32 wait for a function call (such as Waitforsingkobject or waitfor-multipkobjects) to cause the thread to wait for an object, which may have events, mutexes, resource signals M, I/O operations, processes, threads, window messages, and so on. If the time quota for the waiting thread is left, when the wait event occurs, the thread's time quota is reduced by 1, the equivalent of 1/3 clock intervals; If the thread's priority is greater than or equal to 14, the thread's priority is reset when the wait event occurs.

2. Preemptive

When a high priority thread waits to complete, a thread waits for an event to appear, a high-priority thread is in a ready state, or a thread's priority is increased or reduced, and a thread in the running state is lower than the ready queue, The system determines whether to let the current thread continue to run or whether the current thread is to be preempted by a high-priority thread. Threads running under User state in Windows 2000/XP can also be preempted by threads running in the kernel state. In determining whether a thread is preempted or not, the scheduler is judged only by thread priority, regardless of the thread's user or kernel state.

When a thread is preempted, it is put back to the team head of the corresponding priority ready queue. When a thread in a real-time priority is preempted, the time quota is reset to a full time slice, while a thread in the dynamic priority is preempted, the time quota is unchanged, and the processor is used again to run out of the remaining time quota.

3. Time quota run out

When a running thread runs out of its time quota, Windows 2000/XP must first determine if the thread's priority needs to be lowered, and then determine if another thread needs to be dispatched to the running state.

If the priority of a thread that has just run out of time quotas is lowered, Windows 2000/XP will look for a more appropriate thread to go into the running state, and the more appropriate thread is the ready thread with the new s value of the thread that has the priority higher than the time quota just completed. If the priority of a thread that has just run out of time quotas has not been lowered and there are other ready threads with the same priority, Windows 2000/XP will select the next thread in the ready queue with the same priority Tochinami into the running state, and the thread that just ran out of time quotas is queued to the queue of Ready queues ( That is, assigning a new time quota and changing the thread state from run to ready state if no ready thread with the same priority is available to run, the thread that just ran out of time quotas gets a new time quota and continues to run.

4. Thread Run End

When the thread finishes running, its state is transferred from the run state to the terminating state. The system dispatches the processor to another thread at this point. The reason that a thread finishes running may be by calling Exhthread and returning from the main function or by another thread calling TerminateThread. If there are no closed handles on the thread object that is in the signaled state, the thread will be removed from the process's thread list and the relevant data structure will be freed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.