1#include <stdio.h>
2#include <stdint.h>
3
4#include <chrono>
5#include <thread>
6
7
8int
9wait_a_while (int microseconds)
10{
11 int num_times = 0;
12 auto end_time = std::chrono::system_clock::now() + std::chrono::microseconds(microseconds);
13
14 while (1)
15 {
16 num_times++;
17 auto wait_time = end_time - std::chrono::system_clock::now();
18
19 std::this_thread::sleep_for(rtime: wait_time);
20 if (std::chrono::system_clock::now() > end_time)
21 break;
22 }
23 return num_times;
24}
25
26int
27main (int argc, char **argv)
28{
29 printf (format: "stop here in main.\n");
30 int num_times = wait_a_while (microseconds: argc * 1000);
31 printf (format: "Done, took %d times.\n", num_times);
32
33 return 0;
34
35}
36

source code of lldb/test/API/commands/expression/timeout/wait-a-while.cpp