在 Linux 上使用 GCC 4.6 和 4.7 运行简单 std::thread 代码时的核心转储
core dump when running simple std::thread code using gcc 4.6 and 4.7 on linux
我不知道我的简单std::thread代码(下面列出)出了什么问题。在 Ubuntu 上使用 gcc 4.6 或最新的 4.7 时,它总是崩溃。我用命令g++ -std=c++11 myfile.cpp
编译了它,g++ -std=gnu++11 myfile.cpp
.
#include <iostream>
#include <thread>
using namespace std;
void func() {
cout << "hellon";
}
int main()
{
std::thread thrd(func);
thrd.join();
}
核心转储的调用堆栈如下所示
#0 0x00007ffff7539445 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff753cbab in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff7b35b0d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7b33c16 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7b33c43 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7b33e6e in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007ffff7b8829c in std::__throw_system_error(int) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff7b89132 in std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8 0x000000000040118e in std::thread::thread<void (&)()> (this=0x7fffffffdeb0, __f=
@0x400e2c: {void (void)} 0x400e2c <func()>) at /usr/include/c++/4.7/thread:133
#9 0x0000000000400e5b in main () at main2.cpp:13
您必须使用 -pthread
选项进行编译。
g++ -std=c++11 -pthread -o main main.cpp
相关文章:
- 在std::thread中,joinable()然后join()线程安全吗
- 分离一个静态常量 std::thread?
- 当指向对象的指针作为参数传递给 std::thread 时,内存可见性
- 如何从 std::thread 返回值
- 将 std::thread by 值推送到列表中
- 转发变量参数列表以模拟 std::thread
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- std::thread 增加 DLL 引用计数,从而防止卸载 DLL
- 如何防止 std::thread 在 QT 中冻结 GUI?
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- 为什么参数在构造 std::thread 时移动两次
- std::thread::_Invoker 使用线程编程时出错
- 在线程 A 中创建一个 std::thread 对象,在线程 B 中连接
- 为什么编译器抱怨 std::thread 参数在转换为右值后必须是可调用的?
- ZeroMQ 在使用 std::thread 创建工作线程时崩溃
- 在没有复制构造函数的对象的成员函数中启动 std::thread
- CLang:在 std::thread 中运行函数会导致结构创建BAD_ACCESS
- 调用以CWinThread为基的类运算符()的std::thread失败
- 如何通过std::thread生成多个线程
- std::future::get()或std::future::wait()是std::thread::join()的替