1 | #include <chrono> |
---|---|
2 | #include <cstdio> |
3 | #include <mutex> |
4 | #include <random> |
5 | #include <thread> |
6 | |
7 | #define NUM_OF_THREADS 4 |
8 | |
9 | std::mutex hw_break_mutex; |
10 | |
11 | void |
12 | hw_break_function (uint32_t thread_index) { |
13 | printf (format: "%s called by Thread #%u...\n", __FUNCTION__, thread_index); |
14 | } |
15 | |
16 | |
17 | void |
18 | thread_func (uint32_t thread_index) { |
19 | printf (format: "%s (thread index = %u) starting...\n", __FUNCTION__, thread_index); |
20 | |
21 | hw_break_mutex.lock(); |
22 | |
23 | hw_break_function(thread_index); // Call hw_break_function |
24 | |
25 | hw_break_mutex.unlock(); |
26 | } |
27 | |
28 | |
29 | int main (int argc, char const *argv[]) |
30 | { |
31 | std::thread threads[NUM_OF_THREADS]; |
32 | |
33 | printf (format: "Starting thread creation with hardware breakpoint set...\n"); |
34 | |
35 | for (auto &thread : threads) |
36 | thread = std::thread{thread_func, std::distance(first: threads, last: &thread)}; |
37 | |
38 | for (auto &thread : threads) |
39 | thread.join(); |
40 | |
41 | return 0; |
42 | } |
43 |