C++ 11线程无效

Alw*_*oss 7 c++ multithreading gcc c++11

我的程序如下所示

#include <iostream>
#include <thread>
#include <exception>

void hello()
{
    std::cout << "Hello world!!!!" << std::endl;
}

int main()
{
    std::cout << "In Main\n";
    std::thread t(hello);
    t.join();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我使用以下命令编译它时,我没有错误

g++-4.7 -std=c++11 main.cpp

但是当我运行它时,我得到以下错误

In Main
terminate called after throwing an instance of 'std::system_error'
what():  Operation not permitted
Aborted (core dumped)

有人可以帮助我解决我的错误吗?

Mic*_*ire 10

当我使用GCC的C++ 11线程时,我使用:

g++ -std=c++0x -pthread -g main.cpp
Run Code Online (Sandbox Code Playgroud)

这对我行得通.


bil*_*llz 6

g++使用该-pthread选项编译代码时.

下面是我从stackoverflow中找到的答案: 在g ++中是在后台使用pthreads的C++ 11线程模型?