The Neutral Threaded Apartment

The neutral threaded apartment (NTA) is a new threading model available only on Windows 2000. Although it is not specific to COM+ (classic COM objects can also take advantage of the NTA), the NTA is the recommended threading model for most COM+ objects that do not have a user interface.

The NTA has evolved to address a deficiency in the classic COM MTA threading model: suppose you have an STA client accessing an MTA object. Under classic COM, all cross-apartment calls have to be marshaled via a proxy/stub pair. Even though the object could have handled the call on the client STA thread, the call is marshaled. The stub performed an expensive thread context switch to an RPC thread to access the MTA objects.

There was clearly a need for an apartment that every thread in the process could enter without paying a heavy performance penalty. This is what the NTA is: an apartment that every COM-aware thread can enter. In every process, there is exactly one NTA. The NTA is subdivided (like any other apartment) into contexts. COM objects that reside in the NTA set their threading model value in the Registry to Neutral.

Much like an MTA object, an object marked as neutral will reside in the NTA, regardless of its creator’s apartment. Calls into the NTA are marshaled, but only light-weight proxies are used (to do cross COM+ context marshaling, if needed) because no thread-context switch is involved. A method call on an NTA object is executed on the caller’s ...

Get COM & .NET Component Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.