1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <thread>
void print_numbers(int id) {
for (int i = 0; i < 5; ++i) {
std::cout << "Thread " << id << ": " << i << std::endl;
}
}
int main() {
std::thread t1(print_numbers, 1);
std::thread t2(print_numbers, 2);
t1.join();
t2.join();
std::cout << "All threads completed." << std::endl;
return 0;
}
Back to thread