1 #include <stdio.h>
2 #include <stdint.h>
3 
4 #include <chrono>
5 #include <thread>
6 
7 
8 int
wait_a_while(int microseconds)9 wait_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(wait_time);
20         if (std::chrono::system_clock::now() > end_time)
21             break;
22     }
23     return num_times;
24 }
25 
26 int
main(int argc,char ** argv)27 main (int argc, char **argv)
28 {
29     printf ("stop here in main.\n");
30     int num_times = wait_a_while (argc * 1000);
31     printf ("Done, took %d times.\n", num_times);
32 
33     return 0;
34 
35 }
36