views:

24

answers:

2

Hi everyone, I have developed my first COM component (yes, a newbie in the realm of COM development), initialization is done with COINIT_MULTITHREADED. Also, this COM component is a local server executable. But, I did not add any synchronization code to this component. What do you think: do I have to add CRITICAL_SECTIONs to code or MS COM architecture handles it for me? Thanks in advance.

A: 

Yes.

Use your own mutual exclusion mechanism if you know data is going to be accessed from multiple directions (threads), do not assume MS COM architecture to handle it.

That, at least, what I would have done, based on other technologies Microsoft made which I have experience with - it's like "we make the base, you do the rest". At least with native API.

Wrap the critical section object within a nice class and kick with it!

Poni
Are there threading models for out-proc servers?
sharptooth
@sharptooth: No, COM is guaranteed NOT to be thread-safe.
Quandary
+1  A: 

Since you specified COINIT_MULTITHREADED, COM allows several simultaneous calls to your server and thus you need to do the synchronization yourself.

Use COINIT_APPARTMENTHREADED if you want COM to serialize the calls.

See MSDN for the details.

Timores