1 | #include "attach.h" |
2 | #include <chrono> |
3 | #include <cstdio> |
4 | #include <thread> |
5 | |
6 | using std::chrono::microseconds; |
7 | |
8 | volatile int g_thread_2_continuing = 0; |
9 | |
10 | void * |
11 | thread_1_func (void *input) |
12 | { |
13 | // Waiting to be released by the debugger. |
14 | while (!g_thread_2_continuing) // Another thread will change this value |
15 | { |
16 | std::this_thread::sleep_for(rtime: microseconds(1)); |
17 | } |
18 | |
19 | // Return |
20 | return NULL; // Set third breakpoint here |
21 | } |
22 | |
23 | void * |
24 | thread_2_func (void *input) |
25 | { |
26 | // Waiting to be released by the debugger. |
27 | int child_thread_continue = 0; |
28 | while (!child_thread_continue) // The debugger will change this value |
29 | { |
30 | std::this_thread::sleep_for(rtime: microseconds(1)); // Set second breakpoint here |
31 | } |
32 | |
33 | // Release thread 1 |
34 | g_thread_2_continuing = 1; |
35 | |
36 | // Return |
37 | return NULL; |
38 | } |
39 | |
40 | int main(int argc, char const *argv[]) |
41 | { |
42 | lldb_enable_attach(); |
43 | |
44 | // Create a new thread |
45 | std::thread thread_1(thread_1_func, nullptr); |
46 | |
47 | // Waiting to be attached by the debugger. |
48 | int main_thread_continue = 0; |
49 | while (!main_thread_continue) // The debugger will change this value |
50 | { |
51 | std::this_thread::sleep_for(rtime: microseconds(1)); // Set first breakpoint here |
52 | } |
53 | |
54 | // Create another new thread |
55 | std::thread thread_2(thread_2_func, nullptr); |
56 | |
57 | // Wait for the threads to finish. |
58 | thread_1.join(); |
59 | thread_2.join(); |
60 | |
61 | printf(format: "Exiting now\n" ); |
62 | } |
63 | |