Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sleep for milliseconds

Tags:

c++

linux

sleep

I know the POSIX sleep(x) function makes the program sleep for x seconds. Is there a function to make the program sleep for x milliseconds in C++?

like image 973
Prasanth Madhavan Avatar asked Nov 15 '10 12:11

Prasanth Madhavan


1 Answers

In C++11, you can do this with standard library facilities:

#include <chrono> #include <thread> 
std::this_thread::sleep_for(std::chrono::milliseconds(x)); 

Clear and readable, no more need to guess at what units the sleep() function takes.

like image 161
HighCommander4 Avatar answered Sep 24 '22 19:09

HighCommander4