[C++]我的 COM 服务器需要同步吗?
我已经开发了我的第一个 COM 组件(是的,COM 开发领域的新手),初始化是通过 COINIT_MULTITHREADED 完成的。此外,该 COM 组件是本地服务器可执行文件。但是,我没有向该组件添加任何同步代码。您认为:我是否必须在代码中添加 CRITICAL_SECTION
还是 MS COM 架构为我处理它?提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您指定了 COINIT_MULTITHREADED,COM 允许同时调用您的服务器,因此您需要自己进行同步。
如果您希望 COM 序列化调用,请使用 COINIT_APPARTMENTHREADED。
有关详细信息,请参阅 MSDN。
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.
是的。
如果您知道将从多个方向(线程)访问数据,请使用您自己的互斥机制,不要假设 MS COM 架构可以处理它。
至少,基于我有经验的微软制造的其他技术,我会做的——就像“我们做基础,你做剩下的”。至少使用本机 API 是这样。
将关键部分对象包装在一个漂亮的类中并开始使用它!
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!