HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppCritical

Sleep for milliseconds

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
millisecondssleepfor

Problem

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++?

Solution

Note that there is no standard C API for milliseconds, so (on Unix) you will have to settle for usleep, which accepts microseconds:

#include 

unsigned int microseconds;
...
usleep(microseconds);

Code Snippets

#include <unistd.h>

unsigned int microseconds;
...
usleep(microseconds);

Context

Stack Overflow Q#4184468, score: 533

Revisions (0)

No revisions yet.