Possible Duplicate:
Are Thread.sleep(0) and Thread.yield() statements equivalent?
In my understanding, both Thread.yield() and Thread.sleep(0) should make the CPU rejudge which thread to run by some scheduling algorithm.
The difference is:
Thread.yield() is to give the executive chance to other threads, but Thread.sleep(0) will not, it'll just tell CPU that you should rearrange the executive threads including the current thread itself.
Thread.yield() is just an advice which means it may not be accepted at all, but Thread.sleep(0) will do the rearrangement forcedly.
Are the two above conclusions right?
Thread.Sleep()
has a slightly larger overhead because it creates a system that includes some kind of timer that will wake the process. (Depends on implementation basically)
Bottom line it will call a Yield()
in the end.
Thread.Yield()
Will just give-up the thread's turn, and gain it in the next round.
Thread.Sleep(0)
might have an optimization to just call yield. (Again, implementation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With