如何在不使用线程时让它挂起
我现在的代码
- C/C++ code
DWORD WINAPI FunProc( LPVOID lpParameter // thread data){ hMutex=CreateMutex(NULL,FALSE,"命名"); //线程执行内容 CloseHandle(hMutex);}void xx(){ HANDLE hThread[500]; while(1){ for(i=0;i<线程总数;i++){ //i是线程数 hThread=CreateThread(NULL,0,FunProc,NULL,0,NULL); } WaitForMultipleObjects(i,hThread,TRUE,500); }}可否在线程执行完内容后,挂起,需要时再调用
[解决办法]
定量? select+管道1字节
不定量?互斥锁+条件变量
[解决办法]
在线程函数中WaitForSingleObject()等待某一事件对象
[解决办法]
等待事件。
[解决办法]
void ThreadFun()
{
while(1){
WaitForSingleObject(...);
///....
}
}