//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
 
 

相关文章:

  • 2021-10-09
  • 2021-09-18
  • 2021-12-09
  • 2021-11-14
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2022-01-30
  • 2021-09-17
  • 2021-10-02
  • 2021-11-29
相关资源
相似解决方案