On 08/07/2011 23:46, Paul Borman wrote:
> It is more complicated than that when you have more than a single
> goroutine. This solution also does not allow exiting the program
> anyplace but from realMain. If you are single threaded you can
> implement an exit using panic and a deferred recover, but that will
> not help if you have multiple goroutines. os.Exit doesn't unwind
> anything, panic unwinds the stack it is on. I have brought this up on
> the dev mailing list. I think having the ability to exit a program
> and have all stacks unwound and defers called would require a language
> change.
You want something like atexit(3).
Maybe it could be implemented with os.signal and a slice of functions to
run when the process is about to exit.