Quoted from RHE:
Note that most schedulters do not stop the yielding thread from running in favor of a thread of lower priority.
Originally posted by Rob Ross:
True, but then you'll have to implement code to interrupt the thread from an external thread, otherwise it will sleep forever.
Originally posted by Jose Botella:
The code using sleep(0) waste time in a loop waiting for a condition to be satisfied. Have you considered using wait and notify for the thread that makes the condition true notifies the waiting thread directly, instead of being "prevented" (at impredictable times) by the check of the sleeping thread?