1 #include <stdio.h> 2 #include <fcntl.h> 3 4 #include <chrono> 5 #include <thread> 6 7 volatile bool debugger_flag = true; // The debugger will flip this to false 8 start(void * data)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 here 17 std::this_thread::sleep_for(std::chrono::seconds(1)); 18 } 19 return 0; 20 } 21 main(int argc,char const * argv[])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