A simple delay function:

I just wrote a function to pause the program for 'ms' milliseconds. However, I'm quite unfamiliar with this territory. Can I get someone experienced to comment on this function and/or show me something standard that performs its task?

1
2
3
4
5
6
7
using namespace std::chrono;
void delay(unsigned long ms)
{
    const steady_clock::time_point now = steady_clock::now();
    const steady_clock::time_point finish = now + milliseconds(ms);
    while(steady_clock::now() < finish);
}
Last edited on
You can use std::this_thread::sleep_for().
http://en.cppreference.com/w/cpp/thread/sleep_for
Topic archived. No new replies allowed.