开发者

C++0x "Hello Concurrent World" immediately segfaults on g++/linux?

开发者 https://www.devze.com 2023-01-11 02:35 出处:网络
Browsing through a Currency in C++0x book and thought I would give the sample code a run.It is as basic as it gets.

Browsing through a Currency in C++0x book and thought I would give the sample code a run. It is as basic as it gets.

#include <iostream>
#include <thread>

void hello()
{
    std::cout<<"Hello Con开发者_StackOverflowcurrent World\n";
}


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

    t.join();
}

Compiled with:

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

Goes boom with:

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

Appears to be a setup/library issue of some kind. Anyone familiar with this?


You need to compile/link using the -pthread flag.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号