Microsoft Windows CE:Multiprocessing and Thread Handling

来源:互联网 发布:阿里云邮件 编辑:程序博客网 时间:2024/04/30 18:36

Microsoft Windows CE:Multiprocessing and Thread Handling

Jiang Jiang
http://blog.csdn.net/jznsmail

  Although Windows CE exposes a subset of the same Win32 application programming interface(API) that is used on Windows-based desktop and server computers, the operating system iteself was designed from the ground up , to provide a hightly efficient implementation of the Win32 process and thread model.Windows CE 3.0 supports the following optimizations:
  1.More thread priority levels
  2.Simplified priority-inversion handling
  3.Full support for nested-interrupts
  4.Greater control over timing and scheduling
  A process is a single instance of a running application.All applications that run on Windows CE consist of a process and on or more theads.Each process starts with a single thread, which is know as the "primary thread", and witch provide the resources that are required to run an application.
  A thread is the basic unit to which the Windows CE operating system allocates processor time. Each thread is responsibe for excecuting code within a process, concurrently with other thread in that process and in other processes.
 
Processes
  Windows CE can run up to 32 processes at one time. A minimum of four, and more typically seven or eight, processes are created when the system starts up. These processes provide kernel, device, and file-system service, and other shell and connectivity service. Each process contains all of the resources requiresfor its execution, including a virtual address space, executable code, and object handles. Aprocess can create other processes, called child processes, which can inherit object handles and other access rights from the parent process.
  A process is create with a single therad, often caled the primary thread, but can create additional threads from any of its threas. All threads belonging to a process share its virtual address space and system resources.
  The following illustration shows how memory is allocated in the Windows CE address space.
  +-----------------+-----------
  |   Slot1(32MB    |
  +-----------------+
  |      ...        |
  +-----------------+
  |   Slot32(32MB)  |   2GB virtual address space
  +-----------------+
  |  1GB of virtul  |
  | memory reserved |
  | for large data  |
  |     items       |
  +-----------------+----------
  | Physical memory |
  |   is mapped to  |   2GB physical address space
  | these addresses |
  +-----------------+----------
 
  When a Windows CE-based device starts up, the operating system creates a single, 4 GB virtual address space, which all of processes shared. Part of this address space is divided into 33 "slots" of 32MB each, one for each process's resources. As each process starts, Windows CE assigns it one of the available 32MB slots. Slots zero is reserved for the currently running process.
  When a process starts, the OS stores all of the dynamic-link libraries(DLLs), the stack, the heap, and the data section in the slot that is assigned to process.DLLs are loaded at the top of the slot, and they are followed by the stack, the heap, and the executable file. The bottom 64kilobytes are always left free. DLLs are controlled by the loader, which loads all of the DLLs at the same address for each process.
  Memory-mapped files are an efficient way for two or more processes to share data, especially when the processes are accessing small amounts of data, frequently, and in no particular order. One process creates a named file-mapping object that reserve a region of address space in virtual memory. Other process can share this virtual address space by opening a mapping object by the same name. The system must synchronize read and write operations in the shared memroy space, to prevent one process from overwriting data that is in use by another process, and from freeing the block while the other process is still using it. By creating a named synchronization object, processes can use handles to the shared object to synchronize their activities.
  A thread describes a path of execution within a proces. Every time operating system create a new process, it also create at least one thread. The purpose of creating a thead is to make use of as much of the CPU's time as possible. Each thread shares all of the process's resources, including its address space. In addition, each thread maintains its own stack for storing variables that are referenced in a function. The actual architecture of the stack is dependent on the microprocessor, but typically the default stack limit is 1MB, with 2kb reserved for overflow control. Note that in Windows CE you can't change the stack size when a thread is created. However, you can override the stack limit at compile time. When a thread is created, Windows CE reserves enough memoryspace to accomodate the maximum stack size, and allocates one page of memory to the thread. As the stack grows, the system commits virtual pages from the top down. If no memory space is available, the thread needing the stack space is suspended until the request can be granted and the system will attempt to reclaim reserved, but unused, stack memory from another thread.
  Thread local storage(TLS) is the Win32 mechanism that allows multiple threads of a process to store data that is unique for each thread. There are serveal situations in which you might want a thread to maintain its own data. TLS uses a TLS array to save thread-specific data. When a process is created, Windows CE allocates a 64-slot array for each running process. When a DLL attaches to a process, it searches for a free slot in the array and assigns the slot to the new thread. 

原创粉丝点击