Threads (Windows CE 5.0)

Send Feedback

A thread is a path of execution within a process.

Every time the OS creates a process, it also creates at least one thread. The purpose of creating a thread is to make use of as much of the CPU's time as possible.

For example, in many applications, it is useful to create a separate thread to handle printing tasks so that the user can continue to use the application while it is printing.

Each thread shares all resources of the process, including its address space.

Each thread has a stack. The linker sets the stack size for all threads that are created in a process (/STACK). An individual thread can have its own stack size by calling CreateThread and using the STACK_SIZE_PARAM_IS_A_RESERVATION parameter.

A thread also contains the state of the CPU registers, known as the context, and an entry in the execution list of the system scheduler.

You can use the GetThreadContext function to retrieve the context of the specified thread and the SetThreadContext function to set the context of the specified thread.

Each thread in a process operates independently. Unless you make the threads visible to each other, they execute individually and are unaware of the other threads in a process.

Threads sharing common resources must coordinate their work by using a method of synchronization.

An application starts when the system scheduler gives one of its threads execution control. The system scheduler determines which threads should run and when they should run. Threads of lower priority might need to wait while higher priority threads complete their tasks.

Threads can be in one of the following states:

  • Running
  • Suspended
  • Sleeping
  • Blocked
  • Terminated

When all threads are in the blocked state, Windows CE enters idle mode, which stops the CPU from executing instructions and consuming power.

From idle mode you can switch into suspend mode if there is no user activity. Suspend mode can be controlled by the OEM and applications.

To conserve power, use synchronization objects to block threads that are waiting, instead of creating a thread that polls for status, such as the PeekMessage function.

See Also

Processes and Threads | Creating and Terminating a Thread | Scheduling a Thread | Suspending a Thread | Timing a Thread | Storing Thread-specific Data with Thread Local Storage

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.