Bug in touchForeignPtr?

Glynn Clements glynn at gclements.plus.com
Mon Nov 22 20:24:16 EST 2004


Keean Schupke wrote:

> > "C exit routines" aren't responsible for freeing OS resources; the OS
> > is.
> > 
> > The fact that the SysV IPC objects aren't freed on exit is
> > intentional; they are meant to be persistent. For the same reason, the
> > OS doesn't delete upon termination any files which the process
> > created.
> >   
> > 
> Right, which is why if you want to clean up temporary files, or
> temporary semaphores the OS doesn't do it for you, and you
> need to put some routine inplace to do it (using at_exit)... It
> seems this is the only way to guarantee something gets run when
> a program exits for whatever reason.

There isn't any way to *guarantee* that something is run upon
termination. The program may be terminated due to SIGKILL (e.g. due to
a system-wide lack of virtual memory). If you run out of stack, you
may not be able to call functions to perform clean-up.

Also, if the program crashes, handling the resulting SIGSEGV (etc) is
likely to be unreliable, as the memory containing the resource
references may have been trashed. Calling remove() on a filename which
might have been corrupted is inadvisable.

Also, at_exit() isn't standard. atexit() is ANSI C, but that is only
supposed to be called for normal termination (exit() or return from
main()), not for _exit() or fatal signals.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the Glasgow-haskell-users mailing list