ctrl+c and destructors

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Oct 1 22:12:09 PDT 2013


On Tue, Oct 01, 2013 at 06:44:05PM +0200, deadalnix wrote:
> On Tuesday, 1 October 2013 at 14:53:24 UTC, H. S. Teoh wrote:
> >On Tue, Oct 01, 2013 at 02:06:12PM +0200, deadalnix wrote:
> >>On Monday, 30 September 2013 at 22:55:22 UTC, H. S. Teoh wrote:
> >>>On Mon, Sep 30, 2013 at 08:44:36PM +0200, deadalnix wrote:
> >>>>On Monday, 30 September 2013 at 02:13:47 UTC, H. S. Teoh
> >>>>wrote:
> >>>>>Well, ctrl-C can be handled, so the way I'd do it is to set up a
> >>>>>signal handler for SIGINT and have it write something to a
> >>>>>self-pipe read by the event handler, then the event handler can
> >>>>>throw an Exception (which should cause dtors to run as the stack
> >>>>>unwinds).
> >>>>>
> >>>>
> >>>>No you can't.
> >>>>
> >>>>But you somehow can, if you want to use some black magic :
> >>>>http://www.deadalnix.me/2012/03/24/get-an-exception-from-a-segfault-on-linux-x86-and-x86_64-using-some-black-magic/
> >>>
> >>>We were talking about SIGINT, not SIGSEGV.
> >>>
> >>
> >>That isn't relevant here.
> >
> >Huh? The OP was talking about cleaning up after ctrl-C, not after a
> >segfault. I already know you can't throw exceptions from a segfault
> >(except with heavy trickery, and yes I remember the post you linked
> >and I know how it works).
> >
> >SIGINT is different because it can be handled, and the signal handler
> >can just write a byte to a pipe read by the main event loop, outside
> >of signal handler context.
> >
> 
> The signal handler cannot throw exception. If you want to do so, you
> need the same scafolding.

I know that. :)

All I said was that the signal handler writes a byte to a pipe, which
gets read by the event loop (OUTSIDE of signal handler context), and
then the event loop does the throw.

Now, having *druntime* throw an exception upon ctrl-C is something
totally different, and yes it will require some kind of scaffolding/hack
to make it work, 'cos the exception must propagate outside of signal
handler context.


T

-- 
Notwithstanding the eloquent discontent that you have just respectfully
expressed at length against my verbal capabilities, I am afraid that I
must unfortunately bring it to your attention that I am, in fact, NOT
verbose.


More information about the Digitalmars-d mailing list