由浅入深
#include<thread>
#include<iostream>
using namespace std;
//无参线程
void thread_t1()
{
cout<<"hello c++11 thread"<<endl;
}
//带参线程
void thread_arg(const int a,const int b)
{
cout<< "a=" << a <<" b=" << b <<endl;
}
int main()
{
thread t(thread_t1);
thread_t1(thread_arg,5,6);
t.join(); //等待子线程结束
t1.join();
cout<<"this is main"<<endl;
return 0;
}
本文介绍C++11中线程编程的基础知识,包括无参线程和带参数线程的创建与使用,通过具体示例展示了线程的启动、等待和结束过程。
1528

被折叠的 条评论
为什么被折叠?



