如何杀死或终止增强线程 [英] How to kill or Terminate a boost Thread
本文介绍了如何杀死或终止增强线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想终止或终止加速线程. 代码在这里:
I want to terminate or kill boost thread. code is here:
DWORD WINAPI StartFaceDetector(LPVOID temp)
{
int j=0;
char **argv1;
QApplication a(j,argv1);//add some thread here
gui::VisualControl w;
t=&w;
boost::thread u(&faceThread);
w.show();
a.exec();
// I Want to close u thread here.
return 0;
}
我想在函数返回之前关闭该升压线程. 预先感谢.
I want to close that boost thread before return of function. Thanks in Advance.
推荐答案
在Windows上:
TerminateThread(u.native_handle(), 0);
在Linux/QNX/UNIX/具有pthread支持的任何平台上:
On Linux / QNX / UNIX / any platform with pthread support:
pthread_cancel(u.native_handle());
或
pthread_kill(u.native_handle(), 9);
请注意,Boost作者故意将其忽略了,因为该行为是依赖于平台的,并且定义不明确.但是,您并不是唯一可以使用此功能的人...
Note that boost authors intentionally left this out as the behaviour is platform-dependent and not well defined. However, you're not the only one to ever reach for this functionality...
这篇关于如何杀死或终止增强线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文