问题描述
我想知道是否有人知道可以在c中的Windows中使用的更好的睡眠函数,而不是Sleep(),它需要毫秒输入并且仅保证输入是经过的最短时间.我要经过1毫秒,但实际上会延迟15-16毫秒.有什么方法可以准确设置指定的睡眠时间?
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?
推荐答案
不,不是.当您让程序进入睡眠状态时,您就是在放弃处理器,让操作系统决定下一步要做什么.一旦操作系统处于控制状态,它将决定何时给程序另一个处理时间.这就是为什么您可以指定一个最小值,但是并不能保证操作系统会在任何特定时间恢复到您的进程的原因.
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.
这篇关于Windows中c语言的睡眠功能.是否存在精度更高的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!