今天, 同学问我如何在CB下面不支持并行编程, 其实是编译器不支持。 我在Ubuntu下面测试了一下可以通过, 记录如下
(Ubuntu14.10)新建文件夹, mkdir, cd , 打开vim hello.cpp, 编辑程序如下:
#include <iostream>
#include <thread>
using namespace std;
void hello() {
cout << "hello" << endl;
}
int main()
{
thread t(hello);
t.join();
return 0;
}
保存。
terminal下面查看自己的g++ 版本。
g++ -v
发现自己的版本号是: g++ version 4.9.1
编译运行, 指令如下:
g++ hello.cpp -o hello -pthread -std=c++11
接下来, ls , 会发现多了一个可执行文件hello。
运行:
./hello