Events and Interrupts

# Chapter 13 Events and Interrupts

The normal execution of a Prolog program may be interrupted by Events and Interrupts:

Events
  - 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
  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
  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 asynchronously

- Events
  - Event Identifiers and Event Handling
  - Raising Events
  - Events and Waking
  - Aborting an Execution with Events
- Errors
  - Error Handlers
  - Arguments of Error Handlers
  - User Defined Errors
- Interrupts
  - Interrupt Identifiers
  - Asynchronous handling

1
  This is time that the CPU spends on executing user code, i.e. the ECLiPSe program.
2
  Since implementing reliable timeouts is a nontrivial task, we recommend the use of lib(timeout) for this purpose.
3
  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.
4
  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.