LAST THREAD

The need to synchronize threads is so common that there is an optional phrase, LAST THREAD, that can be used to simplify coding. Note that the thread that LAST THREAD refers to is dynamic, so some care must be taken in its use. LAST THREAD refers to:

  1. the last thread created by the current thread, or the last thread that the current thread communicated with, whichever was the last action
  2. or, if neither of the actions described in (1) has occurred, the parent thread (the thread that created the current thread)

You can use the LAST THREAD phrase to eliminate the need to store a thread handle. For example, the preceding example could also be written as:

PERFORM THREAD OPEN-FILES
PERFORM GET-PASSWORD
WAIT FOR LAST THREAD
PERFORM VALIDATE-PASSWORD

A thread normally ends when the PERFORM or CALL statement that created it completes. You can end a thread earlier in the execution path with the STOP THREAD statement. Used by itself, STOP THREAD terminates the current thread. You can also specify a thread handle to stop another thread. If there is only one thread running, stopping that thread is equivalent to doing a STOP RUN.