包含头文件
#include < thread >
用法很简单,直接看例子:
#include <thread>
void func0(int nArg1,int nArg2) {
cout << nArg1 << nArg2 << endl;
}
void func1() {
// to do
}
int main() {
thread t0(func0, 1, 2);//创建线程
thread t1(func1);//创建线程
//简单分析:第一个入参为回调函数,第二个参数 ~ 第N个参数,对应的是回调函数的入参
//比如 func0(1, 2)
t0.join();//启动线程
t1.join();//启动线程
system("pause");
return 0;
}
简单总结
与传统的创建线程相比较,C++11的thread确实更方便,省去一堆的处理过程;