Handmade Hero»Forums»Code
Stefan
20 posts
Sleep, timeBeginPeriod and Virtualbox
Hi. Thought this may be relevant since Casey is using Virtualbox for windows XP testing.
I'm developing on Windows 7 running in a Virtualbox on Windows 8 host.

Even though timeBeginPeriod returns TIMERR_NOERROR, the sleep function sleeps longer that you ask it to.
The same binary runs without a problem outside Virtualbox.
19 posts
Sleep, timeBeginPeriod and Virtualbox
Seems almost expected with virtual machines.

Maybe you should make sure that your CPU has virtualization extensions (AMD-V or VT-x) and that they're enabled in your BIOS/UEFI settings and in your virtual machine program.
Mārtiņš Možeiko
2562 posts / 2 projects
Sleep, timeBeginPeriod and Virtualbox
That's what Sleep does. It sleeps at least that many milliseconds what you pass in argument. Not exactly. So if you pass value 20, it is perfectly legal to sleep 100 milliseconds.
Stefan
20 posts
Sleep, timeBeginPeriod and Virtualbox
As Casey explained, this is why we call the timeBeginPeriod. It is supposed to force the granularity to 1 ms. If it sleeps longer, the application will close (assert error), since we are then going over the allowed ms per frame (33.333333)
Mārtiņš Možeiko
2562 posts / 2 projects
Sleep, timeBeginPeriod and Virtualbox
Yes, I understand what timeBeginPeriod does. It switches resolution of kernel scheduler. But it is still perfectly legal for Sleep to sleep 100ms if you call timeBeginPeriod(1), kernel scheduler granularity doesn't automatically guarantee precision of Sleep. It might, but that's "undocumented". So it can do whatever it wants.