Re: How do I Sleep for a specified amount of time and relinquish c



"nickdu" <nicknospamdu@xxxxxxxxxxxxxxxx> wrote in message
news:24351809-29FF-434C-9570-1DD1D16E623E@xxxxxxxxxxxxxxxx
No, I'm not mixing Sleep() with SpinWait(). I believe Sleep(), as
implemented by the .NET framework, is not relinquishing control to
runnable
threads.

Sleep() as implemented by the .NET Framework had better just be calling the
Windows API function Sleep(). And that does indeed cause the calling thread
to immediately be suspended, with the next runnable thread being scheduled
for the CPU.

And it even mentions this in the docs. It say something to the
effect of "specify 0 to relinquish control to runnable threads".

That's right. If you don't want to sleep for any specific amount of time,
but still want to give up your timeslice to other runnable threads, you call
Sleep() with the parameter of 0.

That doesn't mean that calling it with some other value doesn't also
relinquish the CPU. It just means that if *all* you want to do is
relinquish the CPU, you can use the value of 0.

And based
on my observations it appears to be behaving that way, not relinquishing
control as soon as I call Sleep(). It appears to be finishing using its
quanta.

Define "my observations". What makes you believe that after calling
Sleep(), your thread continues to run out its timeslice?

And based on the fact that the behavior improved to what I was
looking to achieve when I changed it to a WaitOne(), I would say that
Sleep()
with a non zero value is not really doing what I want, and maybe not doing
what many others are thinking it should do.

You haven't described your observations, so how do you justify your claim
that calling WaitOne() with a timeout "behaves better" than simply calling
Sleep() with the same timeout?

Pete


.



Relevant Pages

  • Re: How do I Sleep for a specified amount of time and relinquish c
    ... Sleep() as implemented by the .NET Framework had better just be calling ... scheduled for the CPU. ... relinquish the CPU, you can use the value of 0. ...
    (microsoft.public.dotnet.framework)
  • Re: How do I Sleep for a specified amount of time and relinquish c
    ... simulated with a Sleep() call. ... continuing to use the thread's quanta I decided to use a wait function to see ... Sleepas implemented by the .NET Framework had better just be calling the ... effect of "specify 0 to relinquish control to runnable threads". ...
    (microsoft.public.dotnet.framework)
  • Re: blockable sleep lock (sleep mutex) 16
    ... code which was calling a lot of mallocs. ... It says "non-sleepable locks", yet it classifies click_instance as sleep mutex. ... In the scheduler, sleeping and blocking are actually quite different. ...
    (freebsd-hackers)
  • Re: Access - Sleep function
    ... For the Sleep command to work while using Shell, the loop that does the ... checking will need to be in VBA, calling Shell each time you loop. ...
    (microsoft.public.access.modulesdaovba)
  • RE: Do you really "sleep" when blocked on a mutex?
    ... and putting them on some queue before calling mi_switch. ... Do you really "sleep" when blocked on a mutex? ... between setrunnableand setrunqueue() - this one simply finds a slot ...
    (freebsd-hackers)

Quantcast