相关疑难解决方法(0)

为什么这个简单的std :: thread示例不起作用?

尝试编译以下示例g++ -std=gnu++0x t1.cpp,g++ -std=c++0x t1.cpp但这两个结果都导致示例中止.

$ ./a.out 
terminate called after throwing an instance of 'std::system_error'
  what():  
Aborted
Run Code Online (Sandbox Code Playgroud)

这是样本:

#include <thread>
#include <iostream>

void doSomeWork( void )
{
    std::cout << "hello from thread..." << std::endl;
    return;
}

int main( int argc, char *argv[] )
{
    std::thread t( doSomeWork );
    t.join();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我在Ubuntu 11.04上尝试这个:

$ g++ --version
g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
Run Code Online (Sandbox Code Playgroud)

谁知道我错过了什么?

c++ multithreading c++11

44
推荐指数
2
解决办法
4万
查看次数

标签 统计

c++ ×1

c++11 ×1

multithreading ×1