There are many functions based on time, it very much depends on the operating system that you use.
The Microsoft API offers Sleep () (capital S), which gives you a millisecond sleep.
On Unix (POSIX) you have nanosleep ().
I think that these two functions should run on most computers.
The implementation will be to use the same loop, but sleeping a bit inside the while () loop. It will still be a pool, like a thing, but much less CPU is faster .
In addition, as pm mentioned, select () has this capability. Just a little confusing to implement, but it is expected to return in time.
source share