[mercury-users] signal handling (was: Native garbage collector)
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Sep 14 19:20:11 AEST 1998
On 14-Sep-1998, Thomas Charles CONWAY <conway at cs.mu.OZ.AU> wrote:
> Fergus Henderson, you write:
> > :- type io_pred == pred(io__state, io__state).
> > :- type io_mode == pred(di, uo) is det.
> >
> > :- pred handler(signal, io_pred, io_pred, io__state, io__state).
> > :- mode handler(in, io_mode, io_mode, di, uo) is det.
...
> > Basically signal handlers are a form of concurrency. You can think
> > of the `handler' predicate above as establishing a new thread which
> > remains blocked until a signal arrives.
...
> Slight bug:
> :- pred handler(signal, io_pred, io_pred, io__state, io__state).
> :- mode handler(in, io_mode, io_mode, di, uo) is cc_multi.
> ^^^^^^^^
Well, I thought about using `cc_multi' before I posted, but I think that
using `det' here is fine.
For anything which does any I/O operations at all, there's always
concurrency with the OS and the other processes in the system.
`cc_multi' on procedures which do I/O should be reserved for procedures
which exhibit *internal* nondeterminism, that is procedures which
can give different results even for the exact same inputs from the
operating system. That's why procedures such as `io__read' and
`io__write' are `det' rather than `cc_multi'.
Now in the case of handler/5, although I said you could think of signal
handling as a form of concurrency, if we're implementing the usual
POSIX signal handling semantics, then the main thread and the signal
handler never actually run concurrently. This means there shouldn't be
any internal nondeterminism. The nondeterminism which arises from the
timing of a signal can reasonably be considered as external
nondeterminism rather than internal nondeterminism.
The distinction between internal and external nondeterminism is
admittedly not always a clear one, so there may be more than one
right answer in cases such as these.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the users
mailing list