WinAPI Sleep() function call sleeps for longer than expected

后端 未结 7 623
清歌不尽
清歌不尽 2020-11-27 07:57

OS: Windows 7

When calling the WinAPI Sleep() function as Sleep(1) the thread actually sleeps for 15ms. I did it 100 times in a loop and the total sleep time was 150

7条回答
  •  醉话见心
    2020-11-27 08:08

    The best articles I have found regarding timing on Windows are here and here. The useful part is that once you change the multimedia timer resolution (e.g. timeBeginPeriod(1) for 1ms) it also affects the Sleep command, because it affects the scheduler in general. This said, achieving 1ms accuracy is not feasible on a non-realtime OS.

提交回复
热议问题