//线程入口函数
void my_func(int a)
{
cout << "我的线程编号为:" << a << endl;
}
vector<thread> mythread;
for (int i = 0; i < 10; i++)
{
mythread.push_back(thread(my_func, i));
}
for (auto pthread = mythread.begin(); pthread != mythread.end(); pthread++)
{//auto是由等号右边的数据类型来确定类型的
//在此等价于vector<thread>::iterator
pthread->join();
}
用容器来管理多个线程
最新推荐文章于 2022-08-22 21:01:36 发布