Types of Join Functions
The Threading package has two types of join functions:
One waits indefinitely for the runnable to complete execution.
One accepts a time-limit for the wait.
Several functions in the Threading package accept a timeout value. This value is meant to specify the amount of “wall-clock” time, in milliseconds, that a function waits before timing out.
NOTE: In some situations, functions that accept a timeout value actually measure duration by the amount of CPU time used, not by the elapsed wall-clock time.
This may result in longer timeout periods than are expected or intended. In these situations, the amount of delay is directly proportional to the percentage of available CPU time granted to the process.
The code segment in
Example 6 illustrates both types of join functions.
Example 6 – Joining runnables in two ways
// Create a threaded runnable
RWThreadFunction myThread = ...
// Start the runnable
myThread.start();
// Wait 1000 msecs (1 second) for the runnable’s thread to exit.
if (RW_THR_TIMEOUT == myThread.join(1000)) {
// The runnable did not finish within one second!
// Now wait as long as it takes...
myThread.join();
}