Windows C/Sleep() 函数在时钟漂移期间将如何运行?

发布于 2024-09-05 08:49:12 字数 100 浏览 7 评论 0原文

如果我运行 Sleep(10000) 之类的命令,并且系统时钟在此期间发生变化,线程是否仍会休眠 10 秒的挂钟时间,或者更少或更多?即 Sleep() 函数是否将毫秒转换为硬件滴答声?

If I run something like Sleep(10000), and the system clock changes during that, will the thread still sleep for 10 seconds of wall-clock time, or less or more? I.e. does the Sleep() function convert milliseconds into hardware ticks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栖竹 2024-09-12 08:49:12

Sleep() 与挂钟时间无关。它基于用于线程调度的同一计时器。

不过,由于系统时钟的频率以及超时后您实际被安排运行的时间,您大多数情况下不会睡正好 10 秒。

Sleep() is independent of the wall-clock time. It is based on the same timer that is used for thread scheduling.

You will mostly not sleep exactly 10 seconds though, due to the frequency of the system clock and when you actually get scheduled to run after the timeout elapses.

死开点丶别碍眼 2024-09-12 08:49:12

据我所知,它没有在任何地方记录下来,但是,是的,你可以放心地假设是这样。如果不这样做的话,那将是相当具有破坏性的,因为日光转换每年发生两次。 记录了等效的内核函数 KeDelayExecutionThread 的 Interval 参数:

指定等待发生的绝对或相对时间(以 100 纳秒为单位)。负值表示相对时间。绝对过期时间跟踪系统时间的任何变化;相对过期时间不受系统时间变化的影响。

It isn't documented anywhere that I know of, but yes, you can safely assume so. It would be quite disruptive if it didn't, daylight transitions happen twice a year. It is documented for the equivalent kernel function, KeDelayExecutionThread's Interval argument:

Specifies the absolute or relative time, in units of 100 nanoseconds, for which the wait is to occur. A negative value indicates relative time. Absolute expiration times track any changes in system time; relative expiration times are not affected by system time changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文