Share via


Scheduling a Thread (Windows Embedded CE 6.0)

1/6/2010

Windows Embedded CE uses a priority-based time-slice algorithm to schedule threads.

Because Windows Embedded 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 of 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, a lower number, 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 set to run to completion, which means that the thread quantum is set to zero. Threads with a quantum set to zero never expire and are never preempted by threads of the same priority. Threads that have a quantum set to zero 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

Concepts

Threads