[MLton-devel] very unfortunate behavior when profiling allocations

Stephen Weeks MLton@mlton.org
Thu, 3 Jul 2003 09:35:58 -0700


> My  notion  of  having an ML atExit was that just as in C, it is useful to be
> able to specify a function to be called on  program  exit.

Oh, the standard basis library has that: OS.Process.atExit.

> One possibility would be that the semantics would run the function
> even if the program `exits' because of an unhandled exception or
> running out of memory.  This should make the implementation easier
> since you then would know that all the stack frames are dead.

I don't think it makes it easier.  Many of the stack frames are dead,
but there's still the first couple, and we still have to worry about
the same IL issues and the possibility of the atExit function
allocating and possibly re-raising.

> The problem I was mentioning was that in C, the  semantics  of  atexit()  are
> that  if you end the program by calling exit(), or having main() return, then
> the functions are called, but if you end the program by  calling  _exit()  or
> getting  a  signal  then  they are not run.  This is used in C since it means
> that when you want to end the program you can decide, at that point,  if  the
> atexit functions should be run.  This is probably not a big deal for ML.

You can make the same decision in SML.  Calling OS.Process.exit causes
the atExit functions to be called, while calling OS.Process.terminate
(or Posix.Process.exit) does not.



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel