3

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 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.

Joe
  • 41,484
  • 20
  • 104
  • 125
Al Kurlansky
  • 275
  • 3
  • 18

2 Answers2

1

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

Community
  • 1
  • 1
Arno
  • 4,994
  • 3
  • 39
  • 63
1

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

James
  • 9,064
  • 3
  • 31
  • 49