std::thread “terminate called without an active exception”
最近在使用std::thread的时候,遇到这样一个问题:
std::thread t(func);
如果不使用调用t.join()就会遇到 "terminate called whithout an active exception",但是在使用boost:thread的时候却没遇到这个问题,google了一下,找到答案:
The trouble you are encountering is a result of the stopThread going out of scope on the stack. The C++ standard has the following to say about this:
30.3.1.3 thread destructor [thread.thread.destr]
~thread();
If joinable() then terminate(), otherwise no effects. [ Note: Either implicitly detaching or joining ajoinable() thread in its destructor could result in difficult to debug correctness (for detach) or performance (for join) bugs encountered only when an exception is raised. Thus the programmer must ensure that the destructor is never executed while the thread is still joinable. — end note ]
What this means is that you should not let threads go out of scope without first calling either join() ordetatch().
The way you describe it, you want the thread to go out of scope without joining so it will continue to run as your application runs. That requires a call to detach(). From there, I can only offer a little wisdom...
大意是说,在~thread();前没有调用join()则会遇到问题很难调试,如果不想调用join()等线程结束的话你可以调用detach().这样就不会遇到"terminate called whithout an active exception"
如下:
{
std::thread t(func);
t.detach();
}
std::thread “terminate called without an active exception”的更多相关文章
- 起thread时,运行报错terminate called without an active exception
I am getting a C++ error with threading: terminate called without an active exception Aborted How to ...
- terminate called without an active exception异常
在gcc4.4下,采用回调机制写了一个类似std::thread的线程类. 但是使用时却发生了核心已转移的错误. main函数调用的代码大致是 int main(int argc, char *arg ...
- C++ std::thread
std::thread Defined in header class thread The class thread represents a single thread of execution. ...
- Correct thread terminate and destroy
http://www.techques.com/question/1-3788743/Correct-thread-destroy Hello At my form I create TFrame a ...
- C++11 并发指南------std::thread 详解
参考: https://github.com/forhappy/Cplusplus-Concurrency-In-Practice/blob/master/zh/chapter3-Thread/Int ...
- Effective Modern C++ Item 37:确保std::thread在销毁时是unjoinable的
下面这段代码,如果调用func,按照C++的标准,程序会被终止(std::terminate) void func() { std::thread t([] { std::chrono::micros ...
- std::thread使用
本文将从以下三个部分介绍C++11标准中的thread类,本文主要内容为: 启动新线程 等待线程与分离线程 线程唯一标识符 1.启动线程 线程再std::threada对象创建时启动.最简单的情况下, ...
- C++11 并发指南二(std::thread 详解)
上一篇博客<C++11 并发指南一(C++11 多线程初探)>中只是提到了 std::thread 的基本用法,并给出了一个最简单的例子,本文将稍微详细地介绍 std::thread 的用 ...
- C++11并发——多线程std::thread (一)
https://www.cnblogs.com/haippy/p/3284540.html 与 C++11 多线程相关的头文件 C++11 新标准中引入了四个头文件来支持多线程编程,他们分别是< ...
随机推荐
- Java构造和解析Json数据的两种方法详解一——json-lib
转自:http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/23/3096001.html 在www.json.org上公布了很多JAVA下的jso ...
- NGINX -- 详解Nginx几种常见实现301重定向方法上的区别
Nginx下常见的301跳转有以下三种,虽然都能达到同样的目的.但是三种写法上还是有区别的,主要的区别是在正则匹配的性能上. 第一种:使用rewrite指令,通过正则匹配所有的URI后再去掉开头第一个 ...
- [转]黄聪:如何使用CodeSmith批量生成代码
本文转自:http://www.cnblogs.com/huangcong/archive/2010/06/14/1758201.html 在上一篇我们已经用PowerDesigner创建好了需要的测 ...
- 多站点IIS用户安全权限设置
如果我们为每个站点都建立一个用户,并设置该用户只有访问本站点的权限,那么就能将访问权限控制在每个站点文件夹内,旁注问题也就解决了 一.这样配置的好处? 不知大家有没有听过旁注?我简单的解释一下吧:有个 ...
- unity GI
占坑 lightmapper有两种: Enlighten, Progressive Enlighten: baked GI 静态物体 离线烘焙 precomputed GI 也是适用于静态物体 F ...
- Vue打包项目图片等静态资源的处理
项目打包,默认是打包在根目录下面的.当然我们可以通过设置,打包到任意子目录中去. 但是,当项目中引入资源的,比如:引入图片资源.js资源.或者字体图标之类的.那么可能在这个中间又会踩坑. 1.在vue ...
- http://blog.csdn.net/xingfuzhijianxia/article/details/6433918
http://blog.csdn.net/xingfuzhijianxia/article/details/6433918
- Tomcat 访问 Manager App,Host Manager
1.启动tomcat,在浏览器输入:http://localhost:8080/ 2.配置tomcat-users.xml 文件 在主目录的cong文件夹下找到tomcat-users.xml 文件 ...
- /dev/null 的含义和用途
/dev/null 代表空设备文件,它等价于一个仅仅写文件,全部写入它的内容都会永远丢失.而尝试从它那儿读取内容则什么也读不到. 0:表示键盘输入(stdin) 1:表示标准输出(stdout),系统 ...
- servlet中ServletConfig的使用
转自:http://www.zzzj.com/html/20090117/69483.html 前言 相对于ServletContext,ServletConfig是针对特定的Servlet的参数或属 ...