signature MLTON_SIGNAL = sig type t type signal = t structure Handler: sig type t val default: t val handler: (Thread.Runnable.t -> Thread.Runnable.t) -> t val ignore: t val isDefault: t -> bool val isIgnore: t -> bool val simple: (unit -> unit) -> t end structure Mask: sig type t val all: t val allBut: signal list -> t val block: t -> unit val getBlocked: unit -> t val isMember: t * signal -> bool val none: t val setBlocked: t -> unit val some: signal list -> t val unblock: t -> unit end val getHandler: t -> Handler.t val handled: unit -> Mask.t val prof: t val restart: bool ref val setHandler: t * Handler.t -> unit val suspend: Mask.t -> unit val vtalrm: t end
Signals handlers are functions from (runnable) threads to (runnable) threads. When a signal arrives, the corresponding signal handler is invoked, its argument being the thread that was interrupted by the signal. The signal handler runs asynchronously, in its own thread. The signal handler returns the thread that it would like to resume execution (this is often the thread that it was passed). It is an error for a signal handler to raise an exception that is not handled within the signal handler itself.
A signal handler is never invoked while the running thread is in a critical section (see MLtonThread). Invoking a signal handler implicitly enters a critical section and the normal return of a signal handler implicitly exits the critical section; hence, a signal handler is never interrupted by another signal handler.
-
type t
-
type Handler.t
-
Handler.default
-
Handler.handler f
-
Handler.ignore
-
Handler.isDefault
-
Handler.isIgnore
-
Handler.simple f
-
type Mask.t
-
Mask.all
-
Mask.allBut l
-
Mask.block m
-
Mask.getBlocked ()
-
Mask.isMember (m, s)
-
Mask.none
-
Mask.setBlocked m
-
Mask.some l
-
Mask.unblock m
-
getHandler s
-
handled ()
-
prof
-
restart
-
setHandler (s, h)
-
suspend m
-
vtalrm
-
the type of signals.
-
the type of signal handlers.
-
handles the signal with the default action.
-
returns a handler h such that when a signal s is handled by h, f will be passed the thread that was interrupted by s and should return the thread that will resume execution.
-
is a handler that will ignore the signal.
-
returns true if the handler is the default handler.
-
returns true if the handler is the ignore handler.
-
returns a handler that executes f () and does not switch threads.
-
the type of signal masks, which are sets of blocked signals.
-
a mask of all signals.
-
a mask of all signals except for those in l.
-
blocks all signals in m.
-
gets the signal mask m, i.e. a signal is blocked if and only if it is in m.
-
returns true if the signal s is in m.
-
a mask of no signals.
-
sets the signal mask to m, i.e. a signal is blocked if and only if it is in m.
-
a mask of the signals in l.
-
unblocks all signals in m.
-
returns the current handler for signal s.
-
returns the signal mask m corresponding to the currently handled signals; i.e., a signal is handled if and only if it is in m.
-
SIGPROF, the profiling signal.
-
dynamically determines the behavior of interrupted system calls; when true, interrupted system calls are restarted; when false, interrupted system calls raise OS.SysError.
-
sets the handler for signal s to h.
-
temporarily sets the signal mask to m and suspends until an unmasked signal is received and handled, at which point suspend resets the mask and returns.
-
SIGVTALRM, the signal for virtual timers.
Interruptible System Calls
Signal handling interacts in a non-trivial way with those functions in the Basis Library that correspond directly to interruptible system calls (a subset of those functions that may raise OS.SysError). The desire is that these functions should have predictable semantics. The principal concerns are:
-
System calls that are interrupted by signals should, by default, be restarted; the alternative is to raise
OS.SysError (Posix.Error.errorMsg Posix.Error.intr, SOME Posix.Error.intr)
This behavior is determined dynamically by the value of Signal.restart. -
Signal handlers should always get a chance to run (when outside a critical region). If a system call is interrupted by a signal, then the signal handler will run before the call is restarted or OS.SysError is raised; that is, before the Signal.restart check.
-
A system call that must be restarted while in a critical section will be restarted with the handled signals blocked (and the previously blocked signals remembered). This encourages the system call to complete, allowing the program to make progress towards leaving the critical section where the signal can be handled. If the system call completes, the set of blocked signals are restored to those previously blocked.