Microsoft Windows CE: multiprocessing and thread handling

Source: Internet
Author: User

Microsoft Windows CE: multiprocessing and thread handling

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 authentication shows how memory is allocated in the Windows CE address space.
+ ----------------- + -----------
| Slot1 (32 MB |
+ ----------------- +
|... |
+ ----------------- +
| Slot32 (32 MB) | 2 GB virtual address space
+ ----------------- +
| 1 GB of invalid ul |
| Memory reserved |
| For large data |
| Items |
+ ----------------- + ----------
| Physical memory |
| Is mapped to | 2 GB 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 32 MB each, one for each process's resources. as each process starts, Windows CE assigns it one of the available 32 MB 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 64 kilobytes 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 special 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 1 MB, with 2 kb 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 suincluded 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.