views:

388

answers:

3

Howdy Overflowites,

I'm looking to see if anyone knows of a higher-resolution "Sleep" API than can be achieved using the following code block:

  ::timeBeginPeriod( 1 );
  ::Sleep( 1 );
  ::timeEndPeriod( 1 );

I'm trying to accomplish some "process balancing" work, and after some experimenting, find I need finer grain control than the process class/thread priority API and native scheduler are providing. The above seems to resolve my problem, but I'm hoping that I can find a reliable mechanism to allow waits at the sub-millisecond level (e.g. .1 to .3 ms)

Thanks!

+1  A: 

Already answered...

http://stackoverflow.com/questions/85122/sleep-less-than-one-millisecond

Nils Pipenbrinck
Thanks - it is the same topic - but as the comments on that post state, that is not a reliable mechanism AFAIK. I'll give it a try. I suspect that access to the high-resolution timers is necessary, and some non-Win32 ::Sleep() call is needed instead.
A: 

Check this question holtavolt http://stackoverflow.com/questions/85122/sleep-less-than-one-millisecond.

smink
A: 

In this case, I think I need to resort to the QueryPerformanceFrequency API, calibrate it against a system clock, and see if it's got the resolution needed.

The boost::xtime suggestion looked a bit unbaked - anyone try this?

Anyone got other ideas?