#include <iostream>
#include <thread>
#include <memory>
#include <vector>
using namespace std;
void sub_thread() {
cout << " thread id " << this_thread::get_id() << endl;
}
int main() {
std::vector<thread> thread_vec;
for (int i = 0; i < 10; i++) {
thread_vec.push_back(thread(sub_thread));
}
for (int i = 0; i < 10; i++) {
thread_vec[i].join();
}
return 0;
}
(base) ~/Desktop$ ./main
thread id thread id thread id thread id thread id 0x7000064870000x70000650a000 thread id 0x7000069220000x70000689f000
0x7000066100000x70000658d000
thread id
thread id 0x7000067160000x70000681c000
thread id 0x700006799000
thread id 0x700006693000