Re: Signal delivered while blocked
- Date: Sat, 19 Aug 2017 01:01:10 -0700
- From: Noah Misch <noah@xxxxxxxxxxxx>
- Subject: Re: Signal delivered while blocked
On Mon, Aug 14, 2017 at 08:03:07AM +0200, Houder wrote:
> On Fri, 4 Aug 2017 00:44:45, Noah Misch wrote:
> > The attached demonstration program blocks signals (with sigprocmask()) to
> > achieve mutual exclusion between signal handlers. It aborts upon receipt of a
> > blocked signal. On "CYGWIN_NT-10.0 2.7.0(0.306/5/3) 2017-02-12 13:18 x86_64",
> > signals regularly arrive despite being blocked. Essential parts of the
> > program include handling two signal numbers and having handlers run for at
> > least 1-2ms; this problem goes away if I remove one of those attributes.
> > GNU/Linux, AIX, Solaris, and "CYGWIN_NT-6.0 1.7.27(0.271/5/3) 2013-12-09 11:57
> > i686" never deliver a blocked signal to this program. I think this Cygwin
> > behavior is non-conforming.
> I do not think that Cygwin is the problem here; your code is the problem
> here, I believe.
> Please, study, for example, chapters 20 and 21 of LPI (Linux Programming
> Interface by Michael Kerrisk).
> (20.10 The Signal Mask (Blocking Signal Delivery)
> (20.13 Changing Signal Dispositions: sigaction())
> You cannot use sigprocmask() like you do; you cannot use SIG_SETMASK as
> a parameter in sigprocmask() within the context of a handler.
What words in those chapters prompted your conclusion? I see nothing in 20.10
or 20.13 about contextual restrictions on SIG_SETMASK. Posix mentions no such
restrictions in its sigprocmask() page, and Posix does say:
The following table defines a set of functions that shall be
async-signal-safe. Therefore, applications can call them, without restriction,
from signal-catching functions.
> Cygwin exhibits misbehaviour in case of your code, because it is slower
> than Linux; however, the code is also wrong for Linux.
> The misbehaviour occurs as result of nested interrupts in case of your
> code (yes, nested interrupts are possible with Linux/Unix!).
> However your code does not experience nesting under Linux, because, as
> I said, Linux is faster than Cygwin.
My code *does* experience signal handler nesting on Linux. In fact, handlers
nest far more quickly than they do under Cygwin. However, all its nesting
under Linux takes place outside the sigprocmask()-bounded critical section.
The algorithm that inspired this test case tolerates that nesting, but it does
not tolerate nesting within the critical section.
> The simplest way to exclude one signal from another, is to specify the
> signal (or signals) in the sa_mask of the sigaction parameter ...
That is true. However, as you discovered in your other thread, it is not an
effective workaround for $SUBJECT.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple