Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out of Process COM Server - function calls and threads

When you have an out of process COM Server and you call a function from a Client inside this server from Thread X inside the client, then how this function get executed in the COM Server?

In the thread its currently executing on, or on its main thread?

like image 253
Tony The Lion Avatar asked Sep 07 '25 10:09

Tony The Lion


2 Answers

Normal COM apartment threading rules are observed. If the object was created by the client in an STA apartment then your client thread need to use a marshaled interface pointer or it gets RPC_E_WRONG_THREAD. The actual method call will execute on the server in its STA thread, it needs to pump a message loop for that to work. Execution is serialized, no locking should be needed.

If it lives in the MTA apartment then the method call will execute on an arbitrary RPC worker thread. And you'll need to take the usual threading precautions.

like image 128
Hans Passant Avatar answered Sep 09 '25 05:09

Hans Passant


Threads do not jump from process to process.

Inside the COM Server, COM listens for incoming method calls and has a pool of threads (specific to this process) to serve the request.

like image 30
Timores Avatar answered Sep 09 '25 04:09

Timores