Threads and Processes

In the minimal COM configuration, Windows CE does not support concurrency management, which means that your application is responsible for synchronizing access to various objects. Multiple threads should not access ActiveX controls, which have thread affinity because of their use of thread-specific resources. Because the COM configuration does not support apartment threading, you cannot implement data synchronization with an apartment-threaded singleton. Instead, you must make explicit calls to thread-synchronization primitives to protect member and global data.

Note that this restriction does not apply to the DCOM configuration.

Specifying the Threading Model

In Windows CE, if the ThreadingModel registry key is not set, the threading model defaults to "Free". In the COM implementation, this is not an issue, because COM on Windows CE does not support other threading models. However, because DCOM on Windows CE supports all threading models and interactions between apartments in the same way that Windows NT does, it is essential that your application set this registry key. In particular, for proxy objects, you must set the ThreadingModel value to "Both", which means that both single-threaded and multithreaded apartment types are supported. If you fail to do this, and a thread that belongs to a different apartment accesses the proxy object, the DCOM run time will attempt to marshal the object and fail.

Note that in Windows NT, if the ThreadingModel registry key is not set, the threading model defaults to "Single". In Windows CE, you must specify the Single threading model explicitly. The following table summarizes the registry settings and their corresponding threading models for both Windows CE and Windows NT.

Windows CE registry key Windows NT registry key Threading model
Single default (not set) Main single-threaded apartment
Apartment Apartment Single-threaded apartment
default (not set) Free Free threading
Both Both Supports both single-threaded and multithreaded apartment models

Thread/Process Affinity and Protected Server Libraries

The DCOM implementation requires every object to have thread/process affinity. This means that threads that are within protected server libraries (PSLs) cannot create or access objects or APIs that are within a DCOM application and that require an explicit concurrency model (that is, objects that must be initialized with a call to the CoInitializeEx function). Specifically, this restriction applies to every call-back that the OS makes to an application, and DLL initialization or termination functions, and any call to a device driver.

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.