brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · d99fb05 Raw
63 lines · cpp
1#include "attach.h"2#include <chrono>3#include <cstdio>4#include <thread>5 6using std::chrono::microseconds;7 8volatile int g_thread_2_continuing = 0;9 10void *11thread_1_func (void *input)12{13    // Waiting to be released by the debugger.14    while (!g_thread_2_continuing) // Another thread will change this value15    {16        std::this_thread::sleep_for(microseconds(1));17    }18 19    // Return20    return NULL;  // Set third breakpoint here21}22 23void *24thread_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 value29    {30        std::this_thread::sleep_for(microseconds(1));  // Set second breakpoint here31    }32 33    // Release thread 134    g_thread_2_continuing = 1;35 36    // Return37    return NULL;38}39 40int main(int argc, char const *argv[])41{42    lldb_enable_attach();43 44    // Create a new thread45    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 value50    {51        std::this_thread::sleep_for(microseconds(1));  // Set first breakpoint here52    }53 54    // Create another new thread55    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("Exiting now\n");62}63