Thread class question

  • Thread starter Thread starter john
  • Start date Start date
J

john

what is the difference between Thread.Sleep and
Thread.SpinWait? They both look like they are used to
make the thread pause for a certian amount of time. what
are the differences?

thanks,
j
 
John,

I believe (and I am not positive here) that SpinWait is really just a
loop that executes for a certain number of iterations. The difference
between Sleep and SpinWait is that Sleep actually will give up its slice of
processing time to other threads, while SpinWait will just enter a loop, not
forefitting the slice it gets.

Hope this helps.
 
john said:
what is the difference between Thread.Sleep and
Thread.SpinWait? They both look like they are used to
make the thread pause for a certian amount of time. what
are the differences?

Thread.SpinWait puts the processor into a short spin-lock, rather than
giving it up to other threads. It's very rarely useful - the point is
to wait for a very short length of time for a condition to crop up
without wanting to go through an unnecessary thread context switch.
 
Back
Top