Quote:Original post by WashuQuoted for truth.
Sleep has never been, and never was designed to be, an accurate method of pausing a thread or process. You have told the system that you wish to nap for AT LEAST n milliseconds.
Having said that, Sleep works perfectly well with timeBeginPeriod(1) on my system (I've tried that a while ago because I wondered myself how well it works). Doing 10.000 Sleep(1) takes little over 10 seconds (4-6 ms more), which I guess is pretty much as good as you can get. To me, it's good enough, anyway.
Quote:As a side note - if you Sleep(0), you essentially give up your spot in the OS timehsare for threads for the current thread, but do not specify a wait time.SwitchToThread is the preferred method here, as it has a much better behaviour. It will run the first ready thread that is scheduled for the same core if there is one, and do nothing otherwise (i.e. the next thread starts with warm caches, and the original thread will still be on the same core unless an urgent reason comes up to move it).
Sleep(0) on the other hand just gives up the time slice and keeps the thread ready, but does not provide any other guarantees. It might run any time later, and in theory on any core that happens to be free at that time.