Sturla Molden skrev:
And just so you don't ask: There should not just be a Sleep(0) in the loop, but a sleep that gets shorter and shorter until a lower threshold is reached, where it skips to Sleep(0). That way we avoid hammering om WaitForMultipleObjects and QueryPerformanceCounter more than we need. And for all that to work better than just giving a timeout to WaitForMultipleObjects, we need the multimedia timer turned on.
The important thing about multimedia timer is that the granularity of Sleep() and WaitForMultipleObjects() by default is "10 ms or at most 20 ms". But if we call timeBeginPeriod(1); the MM timer is on and granularity becomes 1 ms or at most 2 ms. But we can get even more precise than that by hammering on Sleep(0) for timeouts less than 2 ms. We can get typical granularity in the order of 10 µs, with the occational 100 µs now and then. I know this because I was using Windows 2000 to generate TTL signals on the LPT port some years ago, and watched them on the oscilloscope. ~ 15 ms granularity is Windows default. But that is brain dead. By the way Antoine, if you think granularity of 1-2 ms is sufficient, i.e. no need for µs precision, then just calling timeBeginPeriod(1) will be sufficient. Sturla