Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Oct 2009 15:08:17 -0700
From:      Justin Teller <justin.teller@gmail.com>
To:        Jilles Tjoelker <jilles@stack.nl>
Cc:        Kostik Belousov <kostikbel@gmail.com>, freebsd-current@freebsd.org
Subject:   Re: Signals and an exiting thread
Message-ID:  <c47019cc0910021508h1119e6f4ha9a27f4bfd071da2@mail.gmail.com>
In-Reply-To: <20091002201213.GA16633@stack.nl>
References:  <c47019cc0909301102y189a0b8aq47d23efae549f4ab@mail.gmail.com> <20091001120730.GR3130@deviant.kiev.zoral.com.ua> <20091002201213.GA16633@stack.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Oct 2, 2009 at 1:12 PM, Jilles Tjoelker <jilles@stack.nl> wrote:
 ---  snip ---
> SIGKILL cannot be masked. Is it possible that a kill(SIGKILL) is
> assigned to a dying thread and lost?
>
> (SIGSTOP cannot be masked either, but its processing is done by the
> sending thread, so it should be safe.)
>
> I suppose that race can also occur in other uses of pthread_sigmask().
> If a thread masks a signal for a while, and that signal is assigned to
> that thread just as it is executing pthread_sigmask(), it will only be
> processed when that thread unblocks or accepts it, even though other
> threads may have the signal unmasked or be in a sigwait() for it.
> Signals sent after pthread_sigmask() has changed the signal mask are
> likely processed sooner because they will be assigned to a different
> thread or left in the process queue.
>
> POSIX seems to say that signals generated for the process should remain
> queued for the process and should only be assigned to a thread at time
> of delivery.
>
> This could be implemented by leaving signals in the process queue or by
> tracking for each signal in the thread queue whether it was directed at
> the thread and moving the process signals back at sigmask/thr_exit.
> Either way I am not sure of all the consequences at this time.
>
> By the way, SA_PROC in kern_sig.c is bogus, because whether a signal is
> directed at a specific thread depends on how it was generated and not on
> the signal number. Fortunately, it is not used.
>
> --
> Jilles Tjoelker
>

Thanks for the helpful tips.  Andriy's suggestion to only handle
signals from a "sable" thread is a good one -- it would solve some
problems.

However, we did a little more investigation, and the SIGKILL example
Jilles posted happens as well.  We post a SIGKILL to a thread, and the
thread goes away before it can kill the process.  I like the idea of
keeping signals like SIGKILL on the process queue so that it will be
picked up with SOME thread.  The other way is basically what Kostik
suggested -- although I like the idea of copying the signal back to
the proc queue there as well ...

I'll play around with it and see what solves our problem, and I'll
post back here with what I find out.

-Justin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c47019cc0910021508h1119e6f4ha9a27f4bfd071da2>