Why is this Thread java method called join?

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
Joining is the appropriate name for what it does - waiting for the indicated thread to be finished before moving forward. Using join for that predates java.

I figure it's "Wait until this thread joins us here".
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
The terminology confused me at first too.

Basically it's just another word for "waiting for the thread to shutdown."

In C++, and in the Win32 world, when you created a thread, it returned a handle which was also a wait (event) handle.

So when you called a "WaitForSingleObject" on it, it would block the CPU until the thread exited and the handle was signaled.

Join is basically a wrapper around that functionality. Waiting for the thread to shutdown and signal the handle that it's done. My guess is if you look at threads as branching (execution separates here - create a thread), that the join is the opposite of that. Have the branch (the thread) join the main execution further along at this point.

Edit-
Most of the time you can specify a timeout for WaitForSingleObject, like 0, and it will just check to see if the event is signaled. My guess is that your Join command will have an override with a timeout. So you can also use Join to see if your thread has exited correctly by checking the handle.
 
Last edited:

dighn

Lifer
Aug 12, 2001
22,820
4
81
It makes sense if you visualize the threads as lines plotted against time e.g.

Code:
thread 1: ---------- (thread2.join) --------------
thread 2: -----------------/
it's as if the two execution paths "joined" to make one

it's rather symmetrical to the "fork" function, which spawns a new process
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
dighn got it: Join refers to a part of the Fork/Join execution model. The analogy is a path (e.g., a path through a forest). As you walk along the path, it can fork (spawn new threads) or join with another path (another thread).

"Fork"ing (logically) creates a thread of execution; "Join" terminates it (synchronously). These terms are fairly commonplace when talking about concurrency (especially threads and processes). E.g., fork() duplicates the current process (in *nix operating systems).