Purpose
This function can be used to register a cleanup subroutine for the calling thread. In case of an unexpected termination of the calling thread, the system will automatically execute the cleanup subroutine in order for the calling thread to terminate safely. The argument cleanup must be a subroutine expecting exactly one argument. If it is executed, the argument arg will be passed to it as the actual argument.
The argument arg is a generic argument that can be of any type and any rank. The actual argument arg must be a variable, and consequently eligible as a left-value in an assignment statement. If you pass an array section with vector subscripts to the argument arg, the result is unpredictable.
If the actual argument arg is an array section, the corresponding dummy argument in subroutine cleanup must be an assumed-shape array. Otherwise, the result is unpredictable.
If the actual argument arg has the pointer attribute that points to an array or array section, the corresponding dummy argument in subroutine cleanup must have a pointer attribute or be an assumed-shape array. Otherwise, the result is unpredictable.
For a normal execution path, this function must be paired with a call to f_pthread_cleanup_pop.
The argument flag must be used to convey the property of argument arg exactly to the system.
Class
Function
Argument Type and Attributes
Result Type and Attributes
INTEGER(4)
Result Value
On successful completion, this function returns 0. Otherwise, this function returns one of the following errors.