tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Question on signal delivery in threaded applications

On Sun, Sep 20, 2009 at 3:27 PM, Stathis Kamperis 
<> wrote:
> Salute!
> Imagine the following scenario:
> A process spawns a bunch of threads all of which are suspended via
> siguspend(). The threads are ignoring all signals, except for say
> SIGUSR1. Piece and quiet. At some point a signal arrives at the
> _process_ level (e.g., via kill). What happens ?
> 1. Some random thread is awaken and the SIGUSR1 signal is delivered to
> it. sigsuspend() returns -1 and sets errno to EINTR for this
> particular thread. The rest of the threads keep sleeping
> uninterrupted.
> 2. All threads awake and race against each other on which one shall
> consume the SIGUSR1.
> 3. Something else.
> I've skimmed through the POSIX specs, but couldn't get a straight answer.
> I'd really appreciate any insights/pointers.
> Best regards,
> Stathis

Hi Stathis,

If my understanding is right, what happens is your first scenario,
with the exception that you don't need to manually block the signal
you've just gotten, since that's the job of the signal handler (see
sigaction(2)). If you want, you can simply block all signals in all
threads, and do sigwait() in a certain thread, then (re)setting some
state in order to let other threads know something's changed.

Home | Main Index | Thread Index | Old Index