|
-
May 28th, 2009, 02:34 AM
#1
Marshalling an interface pointer to multiple worker threads
I have an in-proc COM server object running in an NTA. This COM object creates multiple threads to call one of its methods in parallel to improve performance (oringinally the method was called multiple times synchronously). My worker threads all join an MTA via a call to CoInitialiseEx. One of the paramaters passed to the thread function is an interface pointer to the COM server. I know that I need to marshall the interface pointer, but do I need to marhsall it multiple times for each worker thread by calling CoMarshalInterThreadInterfaceInStream multiple times? And then in each worker thread, I can call CoUnMarshalInterThreadInterfaceInStream to unmarshall the pointer and then make the interface method calls. This way, each thread will use a separate IStream object. Is my understanding of marshalling correct? I thought that marshalling only took part between different apartments, not different threads (if in MTA), but I can't see how I can only marshall once for all the MTA worker threads as this will mean they will all use the same IStream object.
ALso, I have assumed that multiple threads can access the NTA COM server object concurrently, since the MTA threads will be calling it (the caller's thread is used to access objects in an NTA). It was created by another STA client, but I have assumed that the NTA is not fixed to the STA thread that created it - it can be directly accessed by threads of other apartments too.
-
May 29th, 2009, 07:48 AM
#2
Re: Marshalling an interface pointer to multiple worker threads
I am now using the Global Interface Table to marshall my interface pointer, which can then be unmarshelled multiple times - this seems to be a better solution for what I am trying to doie. marshall an interface pointer to multiple worker threads.
But, I still want to check something ...
I have assumed that multiple threads can access the NTA COM server object concurrently, since the MTA threads will be calling it (the caller's thread is used to access objects in an NTA). It was created by another STA client, but I have assumed that the NTA is not fixed to the STA thread that created it - it can be directly accessed by threads of other apartments too. Can anyone verify that my assumtption is correct - my knowledge of NTAs is very limited?
-
May 29th, 2009, 01:23 PM
#3
Re: Marshalling an interface pointer to multiple worker threads
I have been quite a bit away from COM for long and my memory has faded, especially, the apartments always makes me read things a 100 times However, whenever I have had to marshal interface pointers across threads, GIT was what worked great for me. Simple and effective.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|