5. Processes and Threads

< BACK  NEXT >
[oR]

Chapter 5. Processes and Threads

An application can be thought of as the .exe in the object store. When the application is run, a process is created. Therefore, a process is an instance of the application. There can be multiple instances of an application running at any one time; however, in devices such as the Pocket PC, it is considered best practice to have only a single instance running at any one time.

Each process starts off with a single, or primary thread. This thread starts executing code at the entry point, which is typically WinMain or main in most applications. An application can create additional threads to perform background tasks or to wait for some operation to complete. Using additional threads means that the primary thread is always available to deal with user interaction and to repaint the application windows. Multiple threads can be used for tasks such as:

  • Waiting for data to arrive through a serial port, socket, or other communication medium

  • Performing background operations, such as calculations

Using multiple threads provides many advantages but also carries responsibilities. Unless threads are coordinated (or "synchronized") to ensure that no two threads attempt to use the same resource at the same time, they may both end up waiting for the other to complete a task. The techniques available in Windows CE to synchronize threads are covered in Chapter 6.

Not all threads are equal they can be assigned different priorities. Windows CE supports 255 different thread priorities. Of these thread priorities, 248 are used for real-time applications and the remainder for ordinary applications. It is important to use thread priorities responsibly so that threads are neither starved of processor time nor use the processor to the exclusion of other threads.

A process will terminate when the primary thread in that process terminates and the resources used by that application are freed up. Unlike some other operating systems such as UNIX, there is no parent/child relationship. So, when a process terminates, processes created by that process are not automatically terminated.

Windows CE processes share many characteristics with desktop processes running on Windows NT/98/2000, but there are some significant differences. The virtual memory address space is arranged differently. In Windows NT/98/ 2000, each process has its own 4-GB virtual address space that is protected from being accessed by other applications. Remember, these address spaces are virtual, which means that the memory addresses may or may not be backed by real, physical memory.

In Windows CE, the operating system creates a single 4-GB address space. Each process is allocated a 32-MB address space called a "slot". The process uses this address space to map all the Dynamic Link Libraries (DLLs) that it needs to run, as well as data, heap, and stack. Certain larger allocations, such as memory-mapped files, may use address space outside the slot. Chapter 12 describes memory management in more detail. You will see the term "module" used to refer to both applications and Dynamic Link Libraries.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net