Mixing ATL threading modes? 
Author Message
 Mixing ATL threading modes?

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.



Tue, 21 Sep 2004 10:27:03 GMT  
 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.



Wed, 22 Sep 2004 02:36:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. mixing ATL & Non ATL code

2. Mixed-mode dll and ASP.Net

3. mixed mode DLL causing non-continuable exception during process load

4. mixed mode debugger hanging

5. static initialisers in mixed-mode DLLS

6. COM and Mixed Mode DLL

7. Mixed Mode DLL Issues?

8. Mixing real- and protected-mode code

9. Mixing Portrait and Landscape in Duplex mode

10. Mixing MFC and ATL

11. Mixing ATL objects and C++ classes

12. Mixing MFC & ATL

 

 
Powered by phpBB® Forum Software