To implement the (single-threaded) apartment threading model, you must
follow a few rules:
The first thread in the application that gets created is COM's main
thread. This is typically the thread on which WinMain was called. This
must also be the last thread to uninitialize COM.
Each thread in the apartment threading model must have a message loop,
and the message queue must be checked frequently.
When a thread gets a pointer to a COM interface, that pointer may only
be used in that thread.
The single-threaded apartment model is the middle ground between
providing no threading support and full, multi-threading support of the
free threading model. A server committing to the apartment model
promises that the server has serialized access to all of its global data
(such as its object count). This is because different objects may try to
access the global data from different threads. However, the object's
instance data is safe because the methods are always called on the same
thread.
Typically, controls for use in Web browsers use the apartment threading
model because browser applications always initialize their threads as
apartment.
No comments:
Post a Comment