High Resolution version of Sleep() in Windows

  • Thread starter Thread starter Michael Evans
  • Start date Start date
M

Michael Evans

Has anyone come across a way to sleep (suspend execution of current
process while releasing CPU resources in the meantime) for less than a
millisecond in Windows? I know it has been done by third parties such
as with the XBO LLADRV project, but I cannot get even enough support
from them to enable their software in my project. Ideally, I need
something like the unix usleep() function which will do a
processor-friendly sleep for some number of microseconds or
nanoseconds. The LLADRV project supposedly does this for Windows
through low-level access to the OS using their LladrvWaitPreciseTime()
function.

I am using MSVC++ .Net 2003. Thanks for any leads.
 
Michael Evans said:
Has anyone come across a way to sleep (suspend execution of current
process while releasing CPU resources in the meantime) for less than a
millisecond in Windows?

Nope.

The best you can do in an application and without specialized hardware is to
use QueryPerformanceCounter() and QueryPerformanceFrequency() to poll the
counter while spinning a busy loop. But that would not "release CPU
resources in the meantime" as you put it.

Regards,
Will
 
Use SetTimer(...)/OnTimer(...)

The OP's requirement was a preiod "less than a millisecond". And further, as
a concession to the prehistoric versions of Windows, the dispatching of
WM_TIMER messages that are synthesized in response to SetTimer() is deferred
until there is almost nothing else in the queue.

In short, SetTimer() is almost never the right choice.

Regards,
Will
 
Back
Top