如何在C++ 11中干净地终止当前子std ::线程?终止决定是在主线程方法的函数调用深度为4或5时做出的,因此我不想检查每次返回时是否应该终止。我已经看过退出和终止,但它看起来像他们终止整个过程,而不仅仅是当前的线程。终止当前线程
例如:
void A() { B(); ... }
void B() { C(); ... }
void C() { D(); ... }
void D() { /* oops! need to terminate this thread*/ }
void main() {
thread t(A);
}
只从线程main函数返回。 – 2015-03-24 23:21:39
啊,那么不,不可能使用标准的C++功能来退出线程。如果编译器还支持[C11线程](http://en.cppreference.com/w/c/thread),则可以使用例如['thrd_exit'](http://en.cppreference.com/w/c/thread/thrd_exit),否则你不得不依赖平台相关函数,如['pthread_exit'](http://pubs.opengroup。 org/onlinepubs/9699919799/functions/pthread_exit.html)。 – 2015-03-24 23:34:40
所以如果我调用从子线程退出它保证干净地终止整个过程?因为我最终想要终止所有进程,但是在SO上读取某处调用退出子线程并不可靠。 – 2015-03-24 23:40:48