What's the difference between yield() and sleep() in a multithreading program?
What's the difference between yield() and sleep()?
Collapse
X
-
Originally posted by joecchWhat's the difference between yield() and sleep() in a multithreading program?
yield, I'm just being polite so you can enter the room first. When I fall asleep
you most certainly can enter the room first before I wake up.
kind regards,
JosComment
-
Originally posted by JosAHSuppose we both want to enter a room; there's just one door though. When I
yield, I'm just being polite so you can enter the room first. When I fall asleep
you most certainly can enter the room first before I wake up.
kind regards,
JosComment
-
Originally posted by r035198xNotice how telling Jos to sleep will make him sleep whether you want to enter the room or not but when he yields he doesn't enter only if you want to get into the room as well.
something; if no other threads want to do something, I simply continue; if another
thread ayes my question, I pass the processor to the other thread. Note that it
doesn't matter whether or not something synchronized needs to happen; that
scenario still works as always.
kind regards,
JosComment
-
Originally posted by r035198xNotice how telling Jos to sleep will make him sleep whether you want to enter the room or not but when he yields he doesn't enter only if you want to get into the room as well.
Sorry Jos...It seem you are alway on this board.Comment
-
Suppose we are use sleep and set the 100 second to set sleep .so this thread wait 100 second to again start and in this time other thread is running when 100 second complete this thread is return and run.
But in Yield same as sleep but difference is when 100 second is set but no other threads is not Queue in this time then this thread will not wait and again start .
So sleep must be wait to set to specified time however others thread is queue or not but Yield is notComment
-
We call the yeild() method it will give chance to the other thread which is in runnable state .. and our thread will also go to the runnable state...
so that the Cpu Time sheduler may choose another thread to run
or it may choose our thread too...
there is no guarantee...
When we call sleep() method it will go for waiting state
but not to the runnable state so that the Cpu sheduler will pick up another thread from the runnable pool...
and our sleeping thread wakes up after certain amount of time and enter into the runnable state(waiting for cup time)....Comment
Comment