我认为我犯了一个简单的错误,但是由于我注意到这里有很多提升专家,所以我想我会寻求帮助。Boost Thread挂在_endthreadex
我想在Windows XP上使用boost线程(1_40)。主程序加载一个dll,像这样启动线程(请注意,这不是在类中,静态并不意味着对类是静态的,但对文件是私有的)。
static boost::thread network_thread;
static bool quit = false;
HANDLE quitEvent;
//some code omitted for clarity, ask if you think it would help
void network_start()
{
HANDLE *waitHandles = (HANDLE*)malloc(3 * sizeof(HANDLE));
waitHandles[0] = quitEvent;
waitHandles[1] = recvEvent;
waitHandles[2] = pendingEvent;
do {
//read network stuff, or quit event
dwEvents =WaitForMultipleObjects(3, waitHandles, FALSE, timeout);
} while (!quit)
}
DllClass::InitInstance()
{
}
DllClass::ExportedFunction()
{
network_thread = boost::thread(boost::bind<void>(network_start));
}
DllClass::ExitInstance()
{
//signal quit (which works)
quit = true;
SetEvent(QuitEvent);
//the following code is slightly verbose because I'm trying to figure out what's wrong
try {
if (network_thread.joinable()) {
network_thread.join();
} else {
TRACE("Too late!");
}
} catch (boost::thread_interrupted&) {
TRACE("NET INTERRUPTED");
}
}
的问题是,主线程挂在加入,和网线挂在_endthreadex结束。我误解了什么?
你应该为'network_start'定义一个'void *'返回值。 – Potatoswatter 2010-04-08 21:32:40
为什么void *?我的意思是在那里有空白,并且已经编辑了它。我改变了void *,但它并没有解决问题。 – 2010-04-08 21:35:08
我正在考虑pthreads,它需要'void *'。 'void'适用于boost线程,所以这很好。 – Potatoswatter 2010-04-08 21:42:33