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