Front page | perl.perl5.porters |
Postings from July 2014
[perl #81074] Perl reports SIGINT handler "IGNORE" not defined in multi-threaded apps
Thread Next
From:
Tony Cook via RT
Date:
July 28, 2014 04:15
Subject:
[perl #81074] Perl reports SIGINT handler "IGNORE" not defined in multi-threaded apps
Message ID:
rt-4.0.18-12696-1406520915-635.81074-15-0@perl.org
On Wed Dec 11 19:24:18 2013, tonyc wrote:
> On Sun Nov 24 20:27:17 2013, tonyc wrote:
> > I can reproduce this, and I think I understand why it's happening.
> >
> > Perl only sets operating system signal handlers in the main thread,
> > since signal handlers are part of the process state, so the $SIG{INT}
> > = 'IGNORE' in the child thread only sets $SIG{"INT"} without changing
> > the OS level signal handler or actually ignoring the signal.
> >
> > In the root thread, setting $SIG{INT = "IGNORE" results in setting
> > the
> > signal handler to SIG_DFL, so perl's signal handler isn't call, but
> > that doesn't happen in the child thread.
>
> I discussed my solution with Leon in #p5p, and he objected since
> signals sent
> to a thread would no longer be delivered to that thread***.
>
> So I'm suggesting a more complex solution:
>
> 1) If the signal handler is set in the main thread, unless also set in
> the child thread, the signal is delivered to the main thread. This
> solves the case of the operating system delivering a process targetted
> signal to a child thread.
>
> 2) If a child thread set $SIG{FOO} then FOO signals received by that
> thread are delivered to the thread. This allows child threads to
> handle signals, possibled sent with raise() or pthread_kill().
>
> 3) For signals to be handled by a child thread, there must also be a
> non-IGNORE, non-DEFAULT handler in the main thread, which sets the
> POSIX level signal handler. Since POSIX signal handlers are a process
> level resource, we control the actual C level signal handler in the
> main thread.**
>
> 4) If we receive a signal in a child thread and the set handler is
> IGNORE or DEFAULT, it's delivered to the main thread. This allows for
> the case of a signal sent to a process being delivered to the the
> child thread, eg. if the child briefly ignored the signal.
>
> 5) If the main thread receives a signal where the handler is IGNORE,
> it drops the signal on the floor. This handles the case of a child
> setting a handler with POSIX::sigaction() and then terminating.
>
> All of that I believe:
>
> 1) solves this ticket
>
> 2) provides at least a way for a developer to solve 108758.
>
> And hopefully that's all coherent.
>
> Tony
>
> ** I considered keeping a reference count of handlers for each signal,
> but then we need to worry about what happens if the thread terminates
> without cleaning up
>
> *** Leon hasn't reviewed this possible solution.
Here, finally, is a candidate patch.
Tony
---
via perlbug: queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=81074
Thread Next
-
[perl #81074] Perl reports SIGINT handler "IGNORE" not defined in multi-threaded apps
by Tony Cook via RT