st_Request *data;
data->id =10;
data
未初始化,无法取消引用。指针应在取消引用之前指向某个对象。
我不明白这个函数的意义:
void XYZ::Create()
{
mq= new message_queue(open_or_create,"message_queue",100,sizeof(st_Request));
boost:thread workerthread(threadfunc,this);
workerthread.join();
}
你创建了一个新线程,然后阻塞并等待它完成,这样你就可以加入它了。为什么不在这里完成工作,而不是创建一个新的线程并等待它结束呢?
是什么
threadfunc
? 你是说
ThreadFunc
?
这个函数写得很奇怪:
void XYZ::ThreadFunc(void *ptr)
{
XYZ*obj = (XYZ*) ptr;
obj->RecieveMsg();
}
为什么不将该参数传递为
XYZ*
而不是
void*
? Boost.Thread不需要将所有内容都作为
无效*
那是功能吗
static
? 不需要:
struct XYZ {
void threadFunc();
void create();
void recv();
};
void XYZ::threadFunc()
{
recv();
}
void XYZ::create()
{
boost::thread thr(&XYZ::threadFunc, this);
thr.join();
}