Re: fixed time slices?



There is a significant performance cost to increasing the timer frequency.
No the behaviour is not reliable. There is no deterministic timing on
Windows. Your Sleep(1) is only guaranteed to return after _at least_ 1 ms.
It might not return for hours if the system has something better to do than
run your code. You cannot create a reliable 1 ms sleep with a spin wait
loop either because you may be pre-empted at any time and your code may not
run again for hours.



BTW: MSDN says (Sleep function [Base])



"This function causes a thread to relinquish the remainder of its time slice
and become unrunnable for at least the specified number of milliseconds,
after which the thread is ready to run. In particular, if you specify zero
milliseconds, the thread will relinquish the remainder of its time slice but
remain ready. Note that a ready thread is not guaranteed to run immediately.
Consequently, the thread may not run until some time after the specified
interval elapses."



"Jan Bruns" <testzugang_janbruns@xxxxxxxx> wrote in message
news:467b082d$0$14875$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

"Jan Bruns":
From within the callback-procedure, a loop like
for i := 1 to n do sleep(s); // s>0
takes about n*(s+1) ms. What's difrent with this thread?

This is also true for the main thread that called timeBeginPeriod(1).

Is this relyable behaviour? Why does my application need
to call timeBeginPeriod(1) to make the kernel behave as parts of
the SDK define?

Gruss

Jan Bruns



.



Relevant Pages

  • Re: Sleep() is not accurate on XP P4 2.8G
    ... "This function causes a thread to relinquish the remainder of its time slice ... and become unrunnable for at least the specified number of milliseconds, ... In particular, if you specify zero ... Sleep() is not guaranteed to provide anything other than that it will pause ...
    (microsoft.public.win32.programmer.networks)
  • Re: Use of timing loop???
    ... > note that if you call something like nanosleep() for some minimal ... > the loop to execute at the beginning of a time slice every time. ... seems to indicate the time slice for FreeBSD is 20 milliseconds. ...
    (comp.os.linux.development.apps)
  • Re: Thread.Sleep
    ... Causes your thread to wait about 500 milliseconds before it resumes. ... Thread.Sleepgives up your current "time slice", ... > I have code that runs in a loop like this: ... > How would this affect CPU load? ...
    (microsoft.public.dotnet.languages.vb)

Loading