gcc编译选项:c++11 多线程编译

来源:互联网 发布:龙bt发布永久域名 编辑:程序博客网 时间:2024/06/06 01:20

c++11原生支持多线程编程,如下代码(假设文件名为test.cpp):

#include <iostream>
#include <future>
using namespace std;
int main()
{
 auto fr0 = async([](){cout << "Welcome to async" << endl;});
 
 fr0.get();
 
 return 0;
}


这个代码要编译过,需要使用命令:

g++ -Wall -std=c++11 -pthread test.cpp


特殊选项为-pthread,而不是之前的-lpthread

0 0