ctrl+c and destructors

Jonathan M Davis jmdavisProg at gmx.com
Sat Oct 5 19:41:49 PDT 2013


On Saturday, October 05, 2013 16:33:40 Sean Kelly wrote:
> On Oct 5, 2013, at 4:09 PM, Andrej Mitrovic <andrej.mitrovich at gmail.com> 
wrote:
> >> On 9/30/13, Adam D. Ruppe <destructionator at gmail.com> wrote:
> >> Is there anything we can do to automatically clean up if the user
> >> hits ctrl+c on Linux?
> > 
> > What's interesting is I just ran into this SEH enum in druntime for
> > win32 by chance:
> > CONTROL_C_EXIT
> > 
> > But there's no equivalent for linux.
> 
> You need to trap SIGINT. But then you're stuck in a signal handler and so
> can't do much to clean up.

Well, you could do something like set a flag for the various threads to watch 
and throw when it's set to true, but you'd probably have to design everything 
around that to do anything like that, so it's arguably not a particularly good 
solution except in cases where you absolutely need to make sure that stuff 
shuts down correctly, and if you really need that, you should probably take 
another approach (like save regularly), since you can never guarantee that 
your app is going to shut down properly anyway (e.g. the power goes out).

- Jonathan M Davis


More information about the Digitalmars-d mailing list