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?
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.
The Sleep()
function, in most cases, is based off of the system clock. If you call Sleep(10000)
when your system clock is at time T
, then your program will not wake up until (at the soonest) when your system clock reads time T+10000
, regardless of how much time has passed on the wall clock.
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.