1,699 views

1 Answer

1 votes
1 votes

Answer:

A thread will voluntarily give up the CPU by calling thread yield because of the following reasons:

  • Thread in a process cooperate with each other and if a yielding is needed for the betterment of the application, then the thread will yield for sure. 
  • Also, usually the same program writes the code for all the threads in one process.
  • There is no thread scheduler like in the OS. Hence, the programmer doesn't want a thread to go wild and takes the CPU time of the processes forever.
  • To prevent a deadlock of the resource, it might be necessary for a thread to yield itself for continuing the process successfully.

Related questions

0 votes
0 votes
1 answer
3
0 votes
0 votes
1 answer
4