我認爲我犯了一個簡單的錯誤,但是由於我注意到這裏有很多提升專家,所以我想我會尋求幫助。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