• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is guaranteed with join()?

 
E McKenney
Greenhorn
Posts: 18
Chrome VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe I understand how join() normally works: Basically when the calling thread A calls B.join(), it goes into the waiting state until thread B ends, after which thread A becomes runnable again. However, I'm looking for clarification on what happens if join() is called after thread B is already dead (assuming the thread object still exists).

In practice, I imagine that thread A will appear to continue running, since the condition for continuing (i.e. thread B exiting) has already been satisfied. However I'm not sure whether thread A does stop executing briefly (for the few clock cycles necessary for the scheduler to make it runnable again), or if join() basically becomes a no-op when its thread is dead and thus thread A simply continues in the running state.

So, to use the SCJP exam terminology, would you say that the call to join() is "guaranteed to cause the calling thread to stop executing", even given a pathological (but not impossible) case like this? If I see such a statement on the exam, should I consider it to be true or false?

Thanks,
b.
 
Henry Wong
author
Marshal
Pie
Posts: 21420
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The join() method only waits if the thread is still alive. Calling it on a thread that has already completed should not block.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic