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

source code of lldb/test/API/functionalities/thread/create_after_attach/main.cpp