Signals + minimal proposal (was Re: asynchronous exceptions)
droundy at darcs.net
Tue Apr 11 09:35:21 EDT 2006
On Mon, Apr 10, 2006 at 02:19:23PM -0700, John Meacham wrote:
> On Mon, Apr 10, 2006 at 02:58:20PM +0100, Simon Marlow wrote:
> > Suppose I want to do some action with a temporary file:
> > bracket
> > newTempFile
> > (\f -> removeTempFile f)
> > (\f -> doSomethingWith f)
> > Under your scheme, this code doesn't get to remove its temporary file on
> > exit, unless I explicitly add an exit handler that throws an exception
> > to the current thread.
> > I think code like the above should just work. Furthermore, I think it
> > should be an invariant that a thread is never discarded or killed, only
> > sent an exception. Otherwise, how else can I acquire a resource and
> > guarantee to release it when either an exception is raised, the program
> > exits, or the computation completes?
> you ask the system to send you an exception on exit.
(As I'm sure you are aware) I'm with Simon on this one. The default
cleanup handling should "just work", and you shouldn't need to write
special-case code in order to properly clean up. Having exitWith throw
exceptions (as it currently does in ghc) is very nice.
Perhaps we could have a special sort of thread that is just killed upon
exit with no exceptions being raised, but I wouldn't be tempted to use such
a thread... unless I suppose I had some unimportant long-running ffi call
to make, and didn't want exiting to be slowed down by waiting for it to
complete. It would definitely be nice to have interruptible ffi calls (and
not just interruptible by exiting), but I'm not really sure how one would
go about that.
More information about the Haskell-prime