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:
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.