Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one of the following statements about what a notified thread must do before wait() returns is true?

  • A.A notified thread must re-acquire the monitor before it can continue past wait().
  • B.A notified thread continues immediately.
  • C.A notified thread continues immediately because notify() transfers the monitor to it.
  • D.A notified thread continues only after every other waiting thread has been notified.

Answer: A

notify does not hand over the lock. The woken thread is removed from the wait set and re-enabled for scheduling, then competes in the usual way for the monitor, so it cannot proceed until the notifier has left the synchronized region. Only once it regains the monitor does wait() return.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.