c++11/0x多线程编译
//main.cpp
#include <iostream>
#include <thread>
void worker()
{
std::cout << "another thread";
}
int main()
{
std::thread t(worker);
std::cout << "main thread" << std::endl;
t.join();
return 0;
}
编译:
g++ main.cpp -pthread -std=c++0x
注意加-pthread和-std=c++11两个选项。
GCC版本对c++0x的支持见表:
http://gcc.gnu.org/projects/cxx0x.html