I get a similar result for that code. I'm no expert, but I think the problem is the resolution of the timer available to the GetTickCount() function. For example, run this code to see what I mean:
1 2 3 4 5 6 7
|
int main()
{
while(true)
{
cout << GetTickCount() << endl;
}
}
|
The output on my machine looks something like:
29144044
29144044
29144044
29144044
29144044
29144044
29144059
29144059
29144059
29144059
29144059
29144059
29144075
29144075
29144075
29144075
29144075
29144075
29144075
29144091
|
Notice that, although it's running flat-chat, there are distinct 'jumps' in the timer values (around 16ms on my machine). AFAIK, this is a manifestation of the timer resolution.
Now, consider that you're trying to wait 20ms by looking at these values. You'll see that it's possible that around 32ms (if the conditions are right) can pass before your 20ms condition will return. This explains the high value you were getting.
Now, I changed your 'interval' parameter to 200ms, and it gave a much more reasonable result (5070). Perhaps give that a try. If you do actually need to wait for more precise small amounts of time, perhaps others can give you hints on libraries to use.
Hope that helps :). Happy Easter.