Well, it’s Win32 horror going on here.
Sleep(1) in windows is not doing “Sleep 1 ms” like you expect. It calls tell the windows’s kernel to sleep your current thread, and resume it, at least 1ms from now.
And since, there is a usually a lot of thread waiting to run at any given time, you’ll likely wait much more than the specified 1ms duration.
So, as Jules said, this is perfectly correct, since you are giving back your remaining thread timeslice to the system, so the CPU can be used for another, more important, thread.
You should read: http://www.geisswerks.com/ryan/FAQS/timing.html
Jules, you could consider using SwitchToThread whenever possible, for the reason explained below, instead of the old fashionned Sleep() call (or even better, use a WaitForSingleObject on a the soundcard’s async IO, so you actually never “sleep”)
The issue is that since Vista is out, the kernel is doing a lot of statistics on the thread API usage (yes that sound crazy), and when you’re doing a lot of Sleep() calls, you’ll rank lower in the scheduler queue.
Over the running time, our realtime streaming client started to behave way way slower on Vista, and this was due to our sched_yield()/Sleep() calls. When we rewrote the application to use events whenever possible, the performance resumed.