【发布时间】:2014-02-09 16:53:13
【问题描述】:
我在线程中阻塞退出函数时遇到问题。
DWORD WINAPI thread1Func( LPVOID lpParam )
{
exit(0); // Problem is there
while(true){
printf("runnging");
Sleep(1000);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int thread1 = 1;
HANDLE thread1Handle = 0;
thread1Handle = CreateThread( 0, 0,
thread1Func, &thread1, 0, NULL);
WaitForSingleObject(thread1Handle,0);
system("pause");
return 0;
}
不幸的是,我在 main 函数中创建的线程调用了 exit(0) 函数。
thread1Func 不直接调用 exit(0) 语句。它被thread1Func调用的函数调用。所以我不能评论或删除这个声明。
我想阻止线程的退出信号,我该怎么办?
如何阻止来自后台线程的退出信号?
【问题讨论】:
-
你不能,afaik。你介意告诉我们这是什么类型的代码吗?我的意思是,你为什么不能只更改代码?
标签: multithreading winapi c++11 exit-code