跨线程传递 XPCOM 接口指针
我是使用 XPCOM 开发 Firefox 扩展的新手。目前,我正在使用后台线程在 XPCOM 中执行一些工作,并且需要将一个 XPCOM 接口(例如 nsIDomwindow)的指针从主线程传递到该线程。但如果在Windows API函数Createthread中使用该指针作为参数并使用它,则会导致Firefox崩溃。
如何解决这个问题?在MS com中是否有类似的方法来使用CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream? XPCOM只支持单线程吗?
期待您的所有建议和示例代码!提前致谢!
I am new to develop Firefox extension with XPCOM. Currently I am using a background thread to do some work in XPCOM and need to pass a pointer of one XPCOM interface (eg nsIDomwindow) from main thread to that thread. But if use the pointer as the parameter in windows API fundtion Createthread and use it then, that will cause Firefox crash.
How to solve this issue? Is there any similar way to use CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream in MS com? Does the XPCOM only support single thread?
Look forward all your advice and sample code! Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
许多 XPCOM 对象不是线程安全的,特别是任何 DOM 对象只能从主线程访问。要检查对象是否是线程安全的,您必须将其
QueryInterface
到 nsIClassInfo 并检查 nsIClassInfo.flags 是否包含 nsIClassInfo.THREADSAFE 标志。如果是,那么您可以简单地在线程之间传递接口指针。Many XPCOM objects aren't thread-safe, in particular any DOM objects can only be accessed from the main thread. To check whether an object is thread-safe you have to
QueryInterface
it to nsIClassInfo and check whethernsIClassInfo.flags
containsnsIClassInfo.THREADSAFE
flag. If it is then you can simply pass the interface pointer between threads.