36 lines · cpp
1#include "attach.h"2#include <chrono>3#include <cstdio>4#include <fcntl.h>5#include <thread>6 7volatile bool debugger_flag = true; // The debugger will flip this to false8 9void *start(void *data)10{11 int i;12 size_t idx = (size_t)data;13 for (i=0; i<30; i++)14 {15 if ( idx == 0 && debugger_flag)16 std::this_thread::sleep_for(std::chrono::microseconds(1)); // Set breakpoint here17 std::this_thread::sleep_for(std::chrono::seconds(1));18 }19 return 0;20}21 22int main(int argc, char const *argv[])23{24 lldb_enable_attach();25 26 static const size_t nthreads = 16;27 std::thread threads[nthreads];28 size_t i;29 30 for (i=0; i<nthreads; i++)31 threads[i] = std::move(std::thread(start, (void*)i));32 33 for (i=0; i<nthreads; i++)34 threads[i].join();35}36