• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
rupika deval
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is an yield() method? and how is it different from sleep() and wait()
 
Lave Kulshreshtha
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yield relinquish the CPU but sleep does not.
Sleep takes sleep time as input.

-Lave
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Lave]: Yield relinquish the CPU but sleep does not.

Where did you get this idea? That's not even remotely true. Either method may relinquish the CPU, while neither is required to. The sleep() method is more likely to relinquish the CPU, because it generally has a minimum time span during which it cannot resume control of the CPU. Unless you're calling sleep(0), which is generally equivalent to yield().
 
Lave Kulshreshtha
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In one of my java projects it happend, the sleep was consuming CPU continuosly, so I used yield along with sleep to get rid of this problem.

-Lave

Originally posted by Jim Yingst:
[QB][Lave]: Yield relinquish the CPU but sleep does not.

Where did you get this idea? QB]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Similar thread
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic