
Mixing ATL threading modes?
When an MTA thread creates an STA component, COM creates it on so-called
main STA thread - the thread that was first to enter STA (if there are
no such threads, COM creates one). Thus if MTA threads create three STA
objects, all three are created on the same STA thread. If those threads
then call those objects simultaneously, all calls are serialized and
processed by this STA thread one by one.
If you want multiple STA threads, you should create them explicitly.
Such a thread can then create an STA object, marshal its interface
pointers to MTA, and spin a message pump.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Quote:
> I have a question. If I have a multi-threaded COM server residing in
the
> MTA, what happens if it uses a single-threaded apartment based COM
object as
> a helper to perform its duties?
> If I understand COM ATL, then the (for example) 3 threads currently
hitting
> the MTA object each called CoInitialize (I hope). No change to the
threading
> happens when we go into the MTA... Each thread is a thread, is a
thread, is
> a thread. Then they call into the STA object from within the MTA
object.
> There should be a new apartment automatically created for each STA
object /
> thread combination (3 apartments in this case), right?
> In a nutshell, will the STA object cause my MTA object to stall? If
each STA
> object gets its own apartment, then it should not stall, right?
> Thanks folks!
> Greg.