Based on a commit to the Go runtime I just ran some tests using the undocumented CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag with CreateWaitableTimerEx. It allows high-resolution waits without raising the timer interrupt frequency. In some cases these waits can be much shorter than those that are possible with the other mechanisms.
My test code is available here:
https://github.com/randomascii/blogstuff/blob/main/timer_interval/waitable_timer.cppI verified these results, from the original Go commit message:
1. CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is off - timeBeginPeriod is off
delay is 1000 us - slept for 4045 us
delay is 100 us - slept for 3915 us
delay is 10 us - slept for 3291 us
delay is 1 us - slept for 2234 us
2. CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is on - timeBeginPeriod is off
delay is 1000 us - slept for 1076 us
delay is 100 us - slept for 569 us
delay is 10 us - slept for 585 us
delay is 1 us - slept for 17 us
3. CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is off - timeBeginPeriod is on
delay is 1000 us - slept for 742 us
delay is 100 us - slept for 893 us
delay is 10 us - slept for 414 us
delay is 1 us - slept for 920 us
4. CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is on - timeBeginPeriod is on
delay is 1000 us - slept for 1466 us
delay is 100 us - slept for 559 us
delay is 10 us - slept for 535 us
delay is 1 us - slept for 5 us
In other words, this lets a program do shorter sleeps than were previously possible without having to raise the timer interrupt frequency.
To see it demonstrate its abilities you need to run it on a machine running 1803 or later because that is when I believe this flag was created. For full results you need to run it on a machine that doesn't have the timer interrupt frequency raised (my test code checks for that) which is usually not the case for Googler machines because of Go programs that are always running which raise the timer interrupt frequency (the aforementioned Go runtime commit should allow this to be fixed).
It's an intriguing possibility to be able to get more accurate timers without raising the timer interrupt frequency. On the other hand it raises the possibility of abuse since it will desynchronize our timers and could make things consume more power.
I thought I'd open this up for some initial discussion before filing a bug.
--