Module signal [preloaded]

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:

call_cleanup(B, C):
The predicate succeeds whenever B succeeds. Additionally the clean-up C is called when B fails or deterministically succeeds. The clean-up C is also called when a cut or an exception happens inside B or in the continuation.
setup_call_cleanup(A, B, C):
The predicate succeeds when the setup A succeeds once and whenever B succeeds. Additionally the clean-up C is called when B fails or deterministically succeeds. The clean-up C is also called when a cut or an exception happens inside B or in the continuation. The setup A and the clean-up C are called with the signal mask temporarily set to off.
sys_atomic(A):
The predicate succeeds whenever A succeeds. The goal A is invoked with the signal mask temporarily set to off.
sys_ignore(A):
The predicate succeeds whenever A succeeds. The goal A is invoked with the mode cloak temporarily set to on.

The following Prolog flags for signal handling are provided:

sys_mask:
Legal values are on and off. The flag indicates whether the interpreter currently accepts signals. Default value is on. The value can be changed.
sys_choices:
The current number of choice points. The value cannot be changed.
sys_variables:
The current serial number. The value cannot be changed.

Comments