当从线程调用 XPCOM 函数时 Firefox 崩溃
我想从 XPCOM 组件创建一个线程... 这是一个代码
nsresult rv = NS_OK;
nsCOMPtr<Callback> obj = do_CreateInstance("@jscallback.p2psearch.com/f2f;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
char* str="Hello from C++";
obj->Status(str);
_beginthread( (void(*)(void* ))&(P2P::test), 0,obj);
return NS_OK;//obj->Status(str);
这是一个线程函数
当我在调用线程之前调用函数时 它可以工作 但是一旦我写了类似 obj->Status(temp);
的东西,Firefox就会在这个函数上崩溃称呼
class P2P{
static char RecvBuf[1024];
public:
static void test(Callback* obj){
// char* temp="Hellllllooo";
// obj->Status(temp);
return;
}
};
I want to create a thread from XPCOM Component ...
Here is a code for that
nsresult rv = NS_OK;
nsCOMPtr<Callback> obj = do_CreateInstance("@jscallback.p2psearch.com/f2f;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
char* str="Hello from C++";
obj->Status(str);
_beginthread( (void(*)(void* ))&(P2P::test), 0,obj);
return NS_OK;//obj->Status(str);
And here is a thread function
When I call function before calling thread It works But As soon as I write something like obj->Status(temp);
Firefox crashes on function this call
class P2P{
static char RecvBuf[1024];
public:
static void test(Callback* obj){
// char* temp="Hellllllooo";
// obj->Status(temp);
return;
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当启动线程的代码超出范围时,nsCOMPtr 将释放该对象,将其引用计数设置为零。此时,该对象将被删除。在超出范围之前,您需要调用 NS_ADDREF(并确保在完成后调用 NS_RELEASE,这样就不会泄漏!)。
When your code that begins the thread falls out of scope, the nsCOMPtr will release the object, putting its refcount to zero. At this point, the object will be deleted. You'll need call NS_ADDREF before you fall out of scope (and be sure to call NS_RELEASE when you are done with it so you don't leak!).