<html>
<body>
At 10:29 AM 8/4/2006, Tim Roberts wrote:<br><br>
<blockquote type=cite class=cite cite="">Ray Schumacher wrote:<br><br>
> I have been trying to use sleep() and
kernel32.QueryPerformanceCounter<br>
> together; I want to delay until a particular tick without trying
up<br>
> the CPU badly.<br>
> However, while time.sleep(.001) relieves the CPU, it has wildly<br>
> unpredictable delay, and sleep(.0001) delays almost nothing at
all!<br>
> (I'm watching the parallel port on a scope).<br>
> If I use a while and just count ticks with
QueryPerformanceCounter(),<br>
> it is very stable and as desired - but it uses 100% CPU.<br>
><br>
> RTAI LINUX has a nanosleep() function that does it all very nicely
on<br>
> our Debian install, is there a parallel in Win32?<br>
> The MS Sleep() function is in integer milliseconds...<br><br>
<br>
No. Windows simply has no mechanism for doing sub-millisecond
sleeps. <br>
The default scheduling interval in XP is 10 milliseconds. You can't
get<br>
an interrupt more granular than that, even in kernel
mode.</blockquote><br>
ahh<br><br>
<blockquote type=cite class=cite cite="">It is<br>
possible to change the scheduling interval to 1 millisecond by using<br>
timeBeginTime, although performance suffers.</blockquote><br>
I see a timeBeginPeriod (?):<br>
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_timegettime.asp" eudora="autourl">
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_timegettime.asp</a>
<br>
used with timeGetTime, normally...<br>
"<b>Windows NT/2000:</b> The default precision of the
<b>timeGetTime</b> function can be five milliseconds or more, depending
on the machine. You can use the
<a href="http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_timebeginperiod.asp">
<b>timeBeginPeriod</a> </b>and
<a href="http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_timeendperiod.asp">
<b>timeEndPeriod</a></b> functions to increase the precision of
<b>timeGetTime</b>. If you do so, the minimum difference between
successive values returned by <b>timeGetTime</b> can be as large as the
minimum period value set using <b>timeBeginPeriod</b> and
<b>timeEndPeriod</b>. Use the <b>QueryPerformanceCounter</b> and
<b>QueryPerformanceFrequency</b> functions to measure short time
intervals at a high resolution, <br><br>
<b>Windows 95:</b> The default precision of the <b>timeGetTime</b>
function is 1 millisecond. In other words, the <b>timeGetTime</b>
function can return successive values that differ by just 1 millisecond.
This is true no matter what calls have been made to the
<b>timeBeginPeriod</b> and <b>timeEndPeriod</b> functions.
"<br><br>
I'll fiddle with these later.<br><br>
<blockquote type=cite class=cite cite="">It is possible to use
QueryPerformanceCounter to do a spin-stall, but<br>
you are essentially in an infinite loop. ALSO remember that you
are<br>
still sharing the CPU with other processes. If another process
decides<br>
it wants to hog the CPU for its whole time slice, you'll lose 10<br>
milliseconds. If a driver decides it needs to do a thermal<br>
recalibration on your disk drive and stalls for 5 milliseconds,
you'll<br>
lose 5 milliseconds.<br><br>
Remember that RTAI LINUX is a real-time operating system designed
for<br>
deterministic processing. Windows most definitely is
not.</blockquote><br>
Thanks for the info,<br>
Ray<br>
</body>
</html>