1. 程式人生 > >gcc編譯選項:c++11 多執行緒編譯

gcc編譯選項:c++11 多執行緒編譯

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