The predicates call_cleanup/2 and setup_call_cleanup/3 install a choice point with a clean-up goal. During a cut the current bindings are visible to the clean-up goal. During an exception the bindings are undone before invoking the clean-up goal. The latter ternary predicate differs from the ISO proposal in that it accumulates errors and in that it throws an error when the clean-up goal fails. The former binary predicate is not part of the ISO proposal.Example:
?- call_cleanup((X = 1; X = 2),(write(X), write(' '))).
X = 1 ;
2 X = 2
?- call_cleanup((X = 1; X = 2),(write(X), write(' '))), !.
1 X = 1
Situations might demand that a secondary thread controls a primary thread. The program-ming interface allows raising a soft signal in a primary Prolog thread from a secondary thread. The method for this purpose is setSignal(). The effect on the primary Prolog thread will be that the signal message is thrown as an error the first possible moment a call port is reached.
The primary Prolog thread might be in a blocking operation. Therefore the method setSignal() also interrupts the primary Prolog thread. The operations of the method setSignal() are disabled as long as the mask flag is set to false. The mask flag can be read off from the corresponding Prolog flag. It can be temporarily reset by the system predicate sys_atomic/1.
The following signal handling predicates are provided:
The following Prolog flags for signal handling are provided: