这是我的问题:
我正在创建线程
HANDLE Threads[THREAD_NUM]
启动线程
void LaunchThread (int i) {
*some checks if the handle is not null etc*;
DWORD threadId;
threads[i] = CreateThread (
NULL,
0,
(LPTHREAD_START_ROUTINE)*StaticMethodInvokingTheThreadFunc,
*StructPassingToThatMethod ( basically have a pointer and thread number)*,
0,
&threadId);
*DebugMessage "thread created"*;
*DebugMessage "with id = (threadId)"*;
}
静态方法调用函数
void DoSmth () {
*DebugMessage "thread func started"*;
...;
*then code with another messages all the way*;
}
等待功能简单
void WaitThread (i){
*DebugMessage "wait for thread to finish"*;
WaitForSingleObject (Threads[i], INFINITE);
}
在主要功能中,序列:
LaunchThread (i);
WaitThread (i);
程序永远不会返回WaitThread ()
函数,并且(!)消息列表看起来像
"thread created"
"thread func started" (and nothing done after that message in DoSmth () func)
"with id = .."
"wait for thread to finish"
即使有 1 个线程也会发生这种情况......对于几个线程我只是有
for ( int t = 0; t < THREAD_NUM; t++)
LaunchThread (t);
和等待线程的相同循环
为什么会这样?我尝试ResumeThread ()
关闭线程句柄并重新启动它,但没有任何帮助。