You can use thread cancelation APIs to cause a thread to end prematurely, or to aid in cleanup when a thread is ended (either prematurely or normally). The thread cancelation APIs work together to provide a mechanism for thread cleanup and protecting threaded resources from cancelation. The thread cancelation APIs only provide clean up and protection in relationship to other pthread APIs. You cannot protect from or clean up when a thread ends as a result of your process ending (normally or abnormally), or when the thread ends via some mechanism outside of the pthread API set. Some examples of mechanisms that can terminate a thread that are outside o the pthread API set are the ENDJOB *IMMED CL command, a thread ending from an unhandled exception, or the operator terminating a thread using the work with threads screen (Option 20 from the WRKJOB display).