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
 
 
posted @ 2014-01-13 21:25  helloweworld  阅读(214)  评论(0编辑  收藏  举报