brintos

brintos / llvm-project-archived public Read only

0
0
Text · 574 B · d86e9da Raw
33 lines · cpp
1#include <chrono>2#include <cstdio>3#include <thread>4 5struct Foo {6  bool enable = true;7  uint32_t offset = 0;8 9  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 18void *background_thread(void *) {19  Foo f;20  for (;;) {21    f.usleep_helper(2);22  }23}24 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