C++0x "Hello Concurrent World"在 g++/linux 上立即出现段错误?

标签 c++ linux multithreading c++11

浏览 C++0x 中的货币一书,并认为我可以运行示例代码。它是最基本的。

#include <iostream>
#include <thread>

void hello()
{
    std::cout<<"Hello Concurrent World\n";
}


int main(int argc, char *argv[])
{
    std::thread t(hello);

    t.join();
}

编译:

g++ -std=c++0x -g -o pgm pgm.cpp

蓬勃发展:

Program received signal SIGSEGV, Segmentation fault.
_dl_fixup (l=0x7ffff7b0992c, reloc_arg=<value optimized out>) at ../elf/dl-runtime.c:147
147     ../elf/dl-runtime.c: No such file or directory.
        in ../elf/dl-runtime.c

似乎是某种设置/库问题。有熟悉这方面的人吗?

最佳答案

您需要使用 -pthread 标志进行编译/链接。

关于C++0x "Hello Concurrent World"在 g++/linux 上立即出现段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3432039/

相关文章:

c++ - 将参数移动到 std::thread 中?

c++ - 如何正确序列化线程访问控制循环的标志

c++ - 线程创建操作是否暗示发生在关系之前?

c++ - 我做错了什么?,在 C++ 中链接

c++ - 用于找出隐式包含哪些文件的 Visual Studio 插件

linux - 带有参数的函数的 Bash 脚本

linux - Golang os.Create 权限被拒绝

linux - Linux 上的 Rebol 2 进程在 "day of heavy load"之后在 SIGTERM 处停止

c++ - 线程安全的缓冲区数组

c++ - SDL_KEYDOWN 和键识别不能正常工作