Chapter 13 Events and Interrupts
The normal execution of a Prolog program may be interrupted by
Events and Interrupts:
they may occur asynchronously (posted by the environment)
or synchronously (raised by the program itself).
- they are handled synchronously by a handler goal that is inserted
into the resolvent.
- the handler can cause the interrupted execution to fail or to abort.
- the handler can interact with the interrupted execution only via
nonlogical features (e.g. global variable or references).
- the handler can cause waking of delayed goals via symbolic triggers.
Errors can be viewed as a special case of events. They are raised by
built-in predicates (e.g. when the arguments are of the wrong type)
and usually pass the culprit goal to the error handler.
Interrupts usually originate from the operating system, e.g. on a Unix
host, signals are mapped to ECLiPSe interrupts.
they occur asynchronously, but may be mapped into a sychronous event.
- certain predefined actions (like aborting) can be performed
- This is time that the
CPU spends on executing user code, i.e. the ECLiPSe program.
- Since implementing reliable timeouts is a
nontrivial task, we recommend the use of
lib(timeout) for this purpose.
This is necessary because the compiler recognises simple
predicates as deterministic at compile time and so if a
simple predicate would cause the invocation of a non-deterministic
error handler, the generated code may no longer be correct.
Note that some events are not errors but are used for different purposes.
In thoses cases the second and third argument are sometimes used
differently. See Appendix C for details.