brintos

brintos / llvm-project-archived public Read only

0
0
Text · 691 B · ac37c5d Raw
36 lines · cpp
1#include <stdio.h>2#include <stdint.h>3 4#include <chrono>5#include <thread>6 7 8int9wait_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 26int27main (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