Hi!

On Tue, Jan 22, 2008 at 12:52:51AM -0800, William Ahern wrote:

>Signal handlers and masks are inherited across fork() and pthread_create().
>And masks are inherited across exec(), too, I think.

>You could add code to each thread to do this. Of course, there are race
>conditions. Imagine if a signal is raised after a thread starts but before
>it can block the signal. This is especially troublesome if you dynamically
>create threads.

A way to avoid the race is to block all signals (using pthread_sigmask)
in main() early and unblock them in *one* thread (which is in duty for
signal handling) *only* later, after having created the other threads.
If you create threads afterwards, block them again before pthread_create
and unblock again afterwards, again. Then the other threads all inherit
the signal mask blocking all signals so there's always only at maximum
one thread which gets the signals.

>With SIGPIPE the answer is simple, though. Block the signal from the main
>thread before creating any other threads. All threads will inherit the
>block, and SIGPIPE can never squeeze through.

I think you mean *ignore* SIGPIPE.

>But, by block I mean actually using sigaction(2) (see the code I posted
>earlier), not by installing a libevent handler. Installing a SIGPIPE handler
>through libevent is pointless and a waste of CPU, and of course it doesn't
>do what you want anyway.

sigaction doesn't *block* signals in Unix/POSIX terminology. It sets up
signal *handling*, to either default handling, user handling or ignoring
the signal.

With libevent, you either ignore a signal using sigaction or you handle
it using libevent and don't touch it yourself with sigaction (but you
may block/unblock it using sigprocmask [in single threaded programs] or
pthread_sigmask [in multithreaded programs]).

Your recommendation of *ignoring* SIGPIPE still stands, and instead you
handle EPIPE in write(2) (or send(2)).

>[...]

Kind regards,

Hannah.
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to