blob: beceb09e5b9c05be4d4519d7342f595f66502736 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <chrono>
#include <thread>
#include <vector>
void thread_function(int my_value) {
int counter = 0;
while (counter < 20) {
counter++; // Break here in thread body.
std::this_thread::sleep_for(std::chrono::microseconds(10));
}
}
int main() {
std::vector<std::thread> threads;
for (int i = 0; i < 10; i++)
threads.push_back(std::thread(thread_function, threads.size() + 1));
for (std::thread &t : threads)
t.join();
return 0;
}
|