为什么 std::make_unique<std::thread>(somefun()) 会在我没有调用 release() 时生成崩溃,并且在调用时会生成崩溃?
Why std::make_unique<std::thread>(somefun()) will generate crash when I haven't call release(), and well when called?
我的代码:
{
t = std::make_unique<std::thread>(std::bind(&Widget::generateNum, this));
}
在~thread()
崩溃,错误msg是' R6010 APORT((已称为'。如果我在破坏t
之前没有打电话给t.release()
,则会导致崩溃。
您必须在破坏线程之前分离或加入线程。
auto t = std::make_unique<std::thread>(std::bind(&Widget::generateNum, this));
// Either do this:
t->detach();
// or do this:
t->join();
// before *t gets destroyed.
选择是否分离还是加入取决于您,但您必须必须做一个或另一个。如果非空std::thread
被销毁,它将调用std::terminate
,结束您的程序。
请参阅std :: thread ::〜线程:
如果
*this
具有关联线程(joinable() == true
(,则称为std::terminate()
。
默认的std::terminate
处理程序调用std::abort
,因此已调用流产的消息。
不要致电T.Release((
致电t.release()
是错误的。这会泄漏std::thread
对象。
相关文章:
- 将方法转换为调用该方法的成员函子对象会导致崩溃
- 在从Qt调用的Python脚本中导入OpenCV崩溃
- 调用 free() 有时会导致程序崩溃
- 调用 java 的回调() 时应用程序崩溃.由于 detatchThread 而获得运行时错误
- Linux c++.在预加载的共享库中定义的基类的崩溃调用函数
- 使用 MS 绕道挂钩在调用钩子函数时崩溃C++
- 矢量迭代器在尝试调用函数时使我的程序崩溃
- 使用唯一指针调用函数会使我的程序崩溃
- 钩/绕道 d3d9 (现在/结束场景) - 似乎调用我的函数然后崩溃
- 亲.InsertAtHead() 调用创建程序崩溃
- 重写require后调用"lua_getfield()"时崩溃
- 当从成员类调用封装的std::begin时,程序崩溃
- Shaderc在android上调用glsl到spv程序集时崩溃
- 从 C# 模块调用C++函数引发随机崩溃
- 从 C# Windows 应用程序调用 C dll 会导致 svchost.exe 崩溃
- EGL 在第一次 opengl 函数调用时崩溃
- winsock连接调用崩溃如果多个线程运行,则在一个线程中正常工作
- 当功能返回时,Linux C 系统()调用崩溃
- 使用迭代器的递归调用崩溃
- 同名类之间的共享 vtables:强制转换为基类型时,对虚拟方法的调用崩溃