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_SECTION
s to code or MS COM architecture handles it for me? Thanks in advance.
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.
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!
精彩评论