开发者

windows c++ and possibility of a microsecond sleep

Is there anyway at all in the windows environment to sleep for ~1 microsecond? After researching and reading many threads and various websites, I have not been able to see that this is possible. Since the scheduler appears to be开发者_Go百科 the limiting factor and it operates at the 1 millisecond level, then I believe it can't be done without going to a real time OS.


It may not be the most portable, and I've not used these functions myself, but it might be possible to use the information in the High-Resolution Timer section of this link and block: QueryPerformanceCounter


Despite the fact that windows is claimed to be not a "real-time" OS, events can be generated at microsecond resolution. The use of a combination of system time (file_time) and the performance counter frequency has been described at other places. However, careful implementation with taking care about processor affinity and process/thread priorities opens the door to timed events at microsecond resolution.

Since the windows scheduler and the windows timer services do rely on the systems interrupt mechanism, the microsecond can only be tuned for by polling. Particulary on multicore systems polling is not so ugly anymore. And the polling only has to last for the shortest possible interrupt period. The multimedia timer interface allows to put the interrupt period down to about 1ms, thus one can get near the desired (microsecond resolution) time and the polling will last for 1ms at most.

My implementation of microsecond resolution time services for windows, test code and an extensive description can be found at the Windows Timestamp Project located at windowstimestamp.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜