Threaded RTS Patch

Simon Marlow simonmar at
Mon Jan 27 06:54:57 EST 2003

> I haven't read Hans Boehm's paper (but will try to get a
> copy once I am off this plane and have a decent Internet
> connection again).  While I understand the problems of
> running finalizers at program exit, I think the OS plus
> explicitly-called-clean-up-routine argument doesn't always
> work either.  An explicitly called clean up routine doesn't
> help when a program terminates abnormally.

Using exception handlers, you can catch most kinds of abnormal
terminations and call your cleanup routines.  The kinds that you can't
catch are:

  - heap overflow.  That's a difficiency that we should fix.

  - RTS internal errors.  It is unlikely that cleanup routines
    will be able to run after a RTS internal error anyway.

  - Other termination conditions, none of which we would be
    able to run finalizers under: signals/process kills, 
    power failure, etc.

  - Deadlock, which should be handled by time-outs in any
    robust system.

So I submit that under all reasonable error conditions it is possible to
ensure that cleanup routines get to run.  GHC uses this method to delete
its temporary files, BTW (and it's currently a bug that a heap overflow
in GHC will cause temporary files to be left lying around).

Admittedly, exceptions aren't properly a part of H98 + FFI.  But I think
we can agree that this is generally a direction that we should be moving
in; Hugs now has exception support that matches GHC's, and the
implementation cost isn't that high for other Haskell implementations.


More information about the FFI mailing list