1 #include <chrono> 2 #include <cstdio> 3 #include <thread> 4 5 struct Foo { 6 bool enable = true; 7 uint32_t offset = 0; 8 usleep_helperFoo9 void usleep_helper(uint32_t usec) { 10 [this, &usec] { 11 puts("Break here in the helper"); 12 std::this_thread::sleep_for( 13 std::chrono::duration<unsigned int, std::milli>(offset + usec)); 14 }(); 15 } 16 }; 17 background_thread(void *)18void *background_thread(void *) { 19 Foo f; 20 for (;;) { 21 f.usleep_helper(2); 22 } 23 } 24 main()25int main() { 26 std::puts("First break"); 27 std::thread main_thread(background_thread, nullptr); 28 Foo f; 29 for (;;) { 30 f.usleep_helper(1); 31 } 32 } 33