On Mon, Jun 2, 2014 at 3:59 PM, Iñaki Baz Castillo <[email protected]> wrote:
> Hi,
>
> In the main thread of my project (which runs a UV loop) I use
> uv_signal to handle USR1 signals.
> Other threads also run their own UV loop but have not a uv_signal handler.
>
> Typically in a multi-thread code one needs to block certain signals in
> all the threads but the one in which it wants to receive it, and that
> is done via:
>
>   sigemptyset(&signal_mask);
>   sigaddset(&signal_mask, SIGUSR1);
>   pthread_sigmask(SIG_BLOCK, &signal_mask, nullptr);
>
> My question is: do I need to run the above code in my threads (in all
> but the main thread)? I ask this because it seems that libuv handle
> signals globally regardless the number of UV loops running in the same
> process. Is it needed then?
>
> Thanks a lot.
>
> PS: More documentation about how libuv internally handles signals
> would be really useful.

You don't _have_ to block signals in other threads but it won't hurt either.

Libuv will catch the signal and route it to the appropriate event
loop, regardless of what thread the signal is delivered on.

Blocking the signal might still be beneficial from a performance
perspective because it stops system calls on your thread from waking
up with an EINTR error code when the signal is delivered.

You should still be prepared to deal with EINTR, of course.  Signals
like SIGSTOP and SIGCONT, for example, can't be blocked.

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to