• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

yield

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would very much appreciate your help with the following? I am confused on this.
With the yield method, is it true a job can be holding back a job
with the same priority and lower priority?
Also, if the priority of jobs is based on time slicing what would happen to the yield method? What would happen if it was
a time-slicing mechanism and different priorities existed?
What is the correct answer below, and why or why not?
Which statement about scheduling thread execution is true?
a The wait() method is called to place a thread at the back of
the runnable pool to allow threads of a lower priority to start.
b The yield() method is called to place a thread at the back of the runnable pool to allow threads of a lower priority to start
c The wait() method is called to place a thread at the back of
the runnable pool to allow thread of the same priority to
start
d The yield method is called to take a thread out of the running state and place into the runnable pool to allow threads
of the same priority to start
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Charlie Swanson:

With the yield method, is it true a job can be holding back a job
with the same priority and lower priority?


The currently executing thread can hold back a thread of equal or lower priority.


Also, if the priority of jobs is based on time slicing what would happen to the yield method?


On a time sliced OS the yield() method will still function correctly. It would just preempt the OS and stop one thread from running and let another of equal priority run. It is a good idea to use yield() just so your code is truly portable, if you don't use yield and your code is run on a non-time sliced machine then the first thread will run to completion (unless a higher priority thread comes along).


What would happen if it was
a time-slicing mechanism and different priorities existed?


Time-slicing will only effect threads of the same priority (as will yield()). On a time sliced machine if there are multiple threads of the same priority and none of a higher priority then the OS will schedule each thread with the same priority a certain portion of processor time. Any threads of lower priority will have to wait until all of the higher ones are done (or are all not runnable for some reason). And any thread of a higher priority would have taken over anyway.


What is the correct answer below, and why or why not?
Which statement about scheduling thread execution is true?
a The wait() method is called to place a thread at the back of
the runnable pool to allow threads of a lower priority to start.
b The yield() method is called to place a thread at the back of the runnable pool to allow threads of a lower priority to start
c The wait() method is called to place a thread at the back of
the runnable pool to allow thread of the same priority to
start
d The yield method is called to take a thread out of the running state and place into the runnable pool to allow threads
of the same priority to start


correct answer would be d.
a and c are wrong because wait() doesn't neccesarily move a thread back to the end of the line. When notify() or notifyAll() is called any waiting thread could be chosen to run. Also, (I could be wrong here - someone let me know if I am) I don't think that just calling wait() will let other threads of the same priority run unless you also call notify() or notifyAll().
b is wrong because yield() lets equal priority threads run not lower priority. If the only other threads are of lower priority the the thread that called yield() will start running again right away.
hope that helped
Dave
reply
    Bookmark Topic Watch Topic
  • New Topic