signal handling (was: Native garbage collector)

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Sep 14 15:46:44 AEST 1998


On 14-Sep-1998, Peter Schachte <pets at cs.mu.OZ.AU> wrote:
> On Mon, Sep 14, 1998 at 09:56:30AM +1000, Thomas Charles CONWAY wrote:
> 
> > One easy way of dealing with interrupts is to provide a way of arranging
> > for a closure to be evaluated on a given interrupt:
> > 
> > :- type signal	== word.
> > 
> > :- pred handler(signal, pred(io__state, io__state), io__state, io__state).
> > :- mode handler(in, pred(di, uo) is det, di, uo) is det.
> 
> But how do you steal the io__state from the predicate that's running
> when the interrupt happens, and put it back when the interrupt closure
> completes?
> 
> This isn't a frivolous question.

I agree with Peter's objection.  I don't see any way of giving the predicate
above a proper declarative semantics.

However, if you change it to take two `pred' arguments, one being the
handler, and the other being the goal over which the handler is scoped,

	:- 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.

	% handler(Signal, HandlerCode, NormalCode)

then you can give it a proper declarative semantics.

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.
The difference between the two predicates handler/4 and handler/5 above
is like the difference between the fork/3 and fork/4 predicates that we
have discussed.

So the declarative semantics is that the io__state passed to the goal
over which the handler is scoped (`NormalCode') includes the effects
of the handler -- the handler is treated as part of the external world
as far as that goal is concerned.  Conversely, the io__state passed to
the handler goal (`HandlerCode') includes the effects of the NormalCode
goal.

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