Processes and Threads

As a multitasking operating system, Windows CE can support up to 32 simultaneous processes, each process being a single instance of an application. In addition, multithreading support allows each process to create multiple threads of execution. A thread is a part of a process that runs concurrently with other parts. Threads operate independently, but each one belongs to a particular process and shares the same memory space. The total number of threads is limited only by available physical memory.

Processes rely on Win32 messages to initiate processing, control system resources, and communicate with the operating system and the user. Each process has its own message queue. For multithreaded applications, each thread also has its own separate message queue. When there are no messages in the queue and the thread is not engaged in any other activity, the system suspends the thread, saving CPU resources.

Although a thread can operate independently, it often needs to be managed by the process. For example, one thread may depend on another for information. Thread synchronization suspends a thread's execution until the thread receives notification to proceed. Windows CE supports thread synchronization by providing a set of wait objects, which stops a thread until a change in the wait object signals the thread to proceed. Supported wait objects include critical sections, named and unnamed events, and named mutex objects. For more information, see Working with Processes and Threads.

Windows CE implements thread synchronization with minimum processor resources — an important feature for many battery-powered devices. And, unlike many operating systems, Windows CE uses the kernel to handle thread-related tasks, such as scheduling, synchronization, and resource management. Consequently, an application need not poll for process or thread completion or perform other thread-management functions.

Because Windows CE is preemptive, it allows the execution of a process or thread to be preempted by one with higher priority. It uses a priority-based, time-slice algorithm, with eight levels of thread priority, for thread scheduling.