1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <thread>
#include <vector>
int main() {
std::vector<std::thread> threads;
for (int i = 0; i < 3; ++i) {
threads.emplace_back([i]() {
std::cout << "Thread " << i << " is running." << std::endl;
});
}
for (auto& t : threads) {
t.join();
}
std::cout << "All threads completed." << std::endl;
return 0;
}
Back to thread