#include <iostream>
#include <string>
using namespace std;
void run(int a){
std::cout << a << std::endl;
std::cout << "子线程ID = " << std::this_thread::get_id() << std::endl;
}
int main()
{
std::vector<std::thread> obj;
//没有使用push_back,省略了先构造再移动的操作
for (int i = 0; i < 5; i++) {
obj.emplace_back(run, i);
}
for (auto it = obj.begin(); it != obj.end(); it++) {
it->join();
}
std::cout << "主线程ID = " << std::this_thread::get_id() << std::endl;
return 0;
}
可以看到,那个线程先执行是不确定的。
最后
以上就是无聊毛豆最近收集整理的关于c++11使用容器管理线程对象的全部内容,更多相关c++11使用容器管理线程对象内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复