Scheduling a Thread (Windows CE 5.0)

Send Feedback

Windows CE uses a priority-based time-slice algorithm to schedule the execution of threads.

Because Windows CE does not have priority classes, the process in which the thread runs does not influence thread priorities.

All priorities can be used in the same process. A thread can have one 256 priorities. The top 249 priorities (zero through 248) are real-time priority levels.

The following table describes the bottom eight priorities (248 through 255).

Priority Description
THREAD_PRIORITY_TIME_CRITICAL Indicates 3 points above normal priority.
THREAD_PRIORITY_HIGHEST Indicates 2 points above normal priority.
THREAD_PRIORITY_ABOVE_NORMAL Indicates 1 point above normal priority.
THREAD_PRIORITY_NORMAL Indicates normal priority.
THREAD_PRIORITY_BELOW_NORMAL Indicates 1 point below normal priority.
THREAD_PRIORITY_LOWEST Indicates 2 points below normal priority.
THREAD_PRIORITY_ABOVE_IDLE Indicates 3 points below normal priority.
THREAD_PRIORITY_IDLE Indicates 4 points below normal priority.

Threads with a higher priority run first.

Threads with the same priority run in a round-robin fashion: when a thread stops running, all other threads of the same priority run before the original thread can continue.

Threads at a lower priority run only after all threads with a higher priority finish or are blocked. If one thread is running and a thread of a higher priority is unblocked, the lower-priority thread is immediately suspended and the higher-priority thread is scheduled.

Threads run for a specific amount of time — called a quantum — that has a default value of 100 milliseconds. OEMs can specify a different quantum.

After a thread has used up its quantum, and if any thread with the same priority is ready to run, the current thread is suspended and another thread is scheduled to run. The only exception to this is if a thread is a "run to completion" thread, which means that the thread quantum is equal to 0. Threads with a quantum set to 0 will never expire and will never be preempted by threads of the same priority. Threads that have a quantum set to 0 cannot be preempted except by a higher priority thread or an interrupt service routine (ISR).

Typically, thread priorities are fixed and do not change. However, there is one exception, called priority inheritance. If a low-priority thread is using a resource that a high-priority thread is waiting to use, the kernel temporarily boosts the priority of the low-priority thread until it releases the resource that is required by the higher-priority thread. For more information on priority inheritance, see Priority Inversion.

To query the priority level of a thread, call the CeGetThreadPriority function.

To change the priority level of a thread, call the CeSetThreadPriority function.

See Also

Threads

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.