cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Sleep alternatives
Sleep alternatives
Mar 24, 2019 at 12:53pm UTC
TredEsty
(2)
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 UTC
salem c
(3700)
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 UTC
jonnin
(11444)
sleep is standard as well (dated). Sleep (caps!) is microsoftism I think.
Mar 24, 2019 at 3:13pm UTC
mbozzi
(3934)
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 UTC
TredEsty
(2)
thanks a lot
Mar 25, 2019 at 2:09pm UTC
deleted account xyzzy
(5768)
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 UTC
Mar 25, 2019 at 2:40pm UTC
Duthomhas
(13214)
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.