Board index » delphi » COM threading models question

COM threading models question

Hi there,

I'm trying to understand the threading models in COM. For that I've written
some sample servers that create factories with the threading model set to
Single, Apartment, Free and Both. All server factories create
MultiInstancing objects.

On the client, I create some threads and use them to manipulate the COM
object.

To test I use some lengthy operation (a loop that displays progress in a
server form). The loop is either performed on the client or on the server.

When I create the COM object in the main thread and supply it to the
subthreads, this does not work. I get the error that I'm trying to use the
object in a different thread than the object was marshalled for. I
understand from the documentation that this is the purpose of using the Free
and Both threading model. So what is going on here?

When I create the COM object in the subthreads I also have an interesting
finding.
I cannot detect any difference between the Single and Apartment model. I
expected the Apartment model to have a better performance because it doesn't
have to serialize the calls.

In summary, I find I have the same functionality options in all models, and
their performance is similar. Am I misunderstanding something?

Any help is appreciated,
  Michel
  Mic...@relational-consultancy.com

 

Re:COM threading models question


Hi,
Have a look at this wonderfull paper writen by Bin Ly :

http://www.castle.net/~bly/Programming/Delphi/Threading

Hoping it will help.

Bye

Michel a crit dans le message <6tnicb$1...@forums.borland.com>...

Quote
>Hi there,

>I'm trying to understand the threading models in COM. For that I've written
>some sample servers that create factories with the threading model set to
>Single, Apartment, Free and Both. All server factories create
>MultiInstancing objects.

>On the client, I create some threads and use them to manipulate the COM
>object.

>To test I use some lengthy operation (a loop that displays progress in a
>server form). The loop is either performed on the client or on the server.

>When I create the COM object in the main thread and supply it to the
>subthreads, this does not work. I get the error that I'm trying to use the
>object in a different thread than the object was marshalled for. I
>understand from the documentation that this is the purpose of using the
Free
>and Both threading model. So what is going on here?

>When I create the COM object in the subthreads I also have an interesting
>finding.
>I cannot detect any difference between the Single and Apartment model. I
>expected the Apartment model to have a better performance because it
doesn't
>have to serialize the calls.

>In summary, I find I have the same functionality options in all models, and
>their performance is similar. Am I misunderstanding something?

>Any help is appreciated,
>  Michel
>  Mic...@relational-consultancy.com

Re:COM threading models question


Thanks Frederic,

For anybody reading this: The paper by Bin Ly is indeed very good (and
READABLE).

http://www.castle.net/~bly/Programming/Delphi/Threading

Thanks a lot for the tip.

Michel

Other Threads