Microsoft Windows CE:Multiprocessing and Thread Handling

本文详细介绍了Windows CE操作系统中进程和线程的管理机制,包括进程创建、资源分配、虚拟地址空间布局、内存映射文件共享、线程创建及调度等关键特性,并探讨了线程局部存储(TLS)的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Microsoft Windows CE:Multiprocessing and Thread Handling

Jiang Jiang
http://blog.youkuaiyun.com/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. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值