开发者

[C++]Does my COM server require synchronization?

开发者_运维问答

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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜