As noted above it is not possible to call e.g. SP_query()
or
even SP_event()
from an arbitrary signal handler. That is, from
signal handlers installed with signal
or
sigaction
. Instead you need to install the signal handler using
SP_signal()
.
When the OS delivers a signal sig
for which
SP_signal(sig,func,user_data)
has been called SICStus will not call
func
immediately. Instead the call to func
will be delayed
until it is safe for Prolog to do so, in much the same way that functions
installed by SP_event()
are handled (this is an incompatible change
from SICStus 3.8 and earlier).
Since the signal handling function func
will not be called
immediately upon delivery of the signal to the process it only makes
sense to use SP_signal()
to handle certain asynchronous signals
such as SIGINT
, SIGUSR1
, SIGUSR2
. Other
asynchronous signals handled specially by the OS, such as SIGCHLD
are not suitable for handling via SP_signal()
. Note that the
development system installs a handler for ‘SIGINT’, and, under
Windows, ‘SIGBREAK’, to catch keyboard interrupts. Under UNIX,
library(timeout)
currently uses SIGVTALRM
.
When func
is called, it cannot call any SICStus API functions
except SP_event()
. Note that func
will be called in the
main thread.