I have a simple code running on my 64 bit machine, Windows 7 as a standard windows application :
do {
DWORD getCurrentTick = GetTickCount();;
Sleep(20);
DWORD nextTick = GetTickCount();
printf("Tick = %d\n", nextTick - getCurrentTick);
} while(TRUE);
I know that a user mode thread sleep is not guaranteed to wake on the requested time but the weird thing is that windows wakes before time comes. look at my output :
Tick = 15
Tick = 16
Tick = 16
Tick = 31
Tick = 15
Tick = 16
Tick = 15
Tick = 16
Tick = 31
My question is how come it wakes before my requested time ? and what can I do to make it more precise ?