Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sleep function in c in windows. Does a function with better precision exist?

I was wondering if anyone knew of a better sleep function that could be used in windows in c, other than Sleep(), which takes a millisecond input and only guarantees that the input is the minimum amount of time that elapses. I am passing in 1 millisecond, but actually getting a 15-16 millisecond delay. Is there any way to accurately set a specified sleep time?


2 Answers

No, not really. When you tell your program to sleep, you're giving up the processor and letting the operating system decide what to do next. Once the operating system is in control, it decides when to give your program another slice of processing time. This is why you can specify a minimum, but there's no guarantee that the OS will get back to your process at any particular time.

like image 117
Bill the Lizard Avatar answered Nov 19 '25 15:11

Bill the Lizard


Look into Multimedia Timers.

like image 23
Joel Lucsy Avatar answered Nov 19 '25 15:11

Joel Lucsy