Re: How do I Sleep for a specified amount of time and relinquish c
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 16 Nov 2006 14:05:17 -0800
"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
.
- Follow-Ups:
- Re: How do I Sleep for a specified amount of time and relinquish c
- From: nickdu
- Re: How do I Sleep for a specified amount of time and relinquish c
- From: Chris Mullins
- Re: How do I Sleep for a specified amount of time and relinquish c
- References:
- Re: How do I Sleep for a specified amount of time and relinquish contr
- From: Michael Nemtsev
- Re: How do I Sleep for a specified amount of time and relinquish c
- From: Michael Nemtsev
- Re: How do I Sleep for a specified amount of time and relinquish contr
- Prev by Date: Re: How do I Sleep for a specified amount of time and relinquish c
- Next by Date: Re: IO.Compression and Encryption
- Previous by thread: Re: How do I Sleep for a specified amount of time and relinquish c
- Next by thread: Re: How do I Sleep for a specified amount of time and relinquish c
- Index(es):
Relevant Pages
|