Sleep alternatives

Mar 24, 2019 at 12:53pm
Hi, i'm new to this forum and i had a question.

Are there any Sleep() alternatives?
Because to me it seems like C++ should have a similar purpose comand.
Mar 24, 2019 at 1:21pm
Well if you're up to date as far as C++11, you can do this.
http://www.cplusplus.com/reference/thread/this_thread/sleep_for/
Mar 24, 2019 at 3:11pm
sleep is standard as well (dated). Sleep (caps!) is microsoftism I think.
Mar 24, 2019 at 3:13pm
sleep is standard

Yeah, but it's POSIX, not ISO C++.

http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html
Mar 25, 2019 at 1:23pm
thanks a lot
Mar 25, 2019 at 2:09pm
There's std::this_thread::sleep_for, and std::this_thread::sleep_until.

Both are for manipulating the execution of a thread.

https://en.cppreference.com/w/cpp/thread/sleep_for
https://en.cppreference.com/w/cpp/thread/sleep_until
Last edited on Mar 25, 2019 at 2:09pm
Mar 25, 2019 at 2:40pm
Use the <thread> libraries to do it, as salem c and Furry Guy pointed to you. Be aware, using them might incur linking additional OS libraries.

If you want to use OS libraries directly, Sleep() is Microsoft’s and usleep() is POSIX. Examples of use:
http://www.cplusplus.com/forum/beginner/139609/#msg738550

The POSIX sleep() is a very crude timer. Avoid it.
Topic archived. No new replies allowed.