[Libevent-users] SIGPIPE in multithreaded program
Ron Arts
ron.arts at neonova.nl
Tue Jan 22 04:04:24 EST 2008
William Ahern schreef:
>
> Signal handlers and masks are inherited across fork() and pthread_create().
> And masks are inherited across exec(), too, I think.
>
Yes, of course, I should've thought of that myself.
> 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.
>
> 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.
>
> 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.
>
Why is it pointless? I indeed noticed it doesn't catch signals (I think
my other signals do not get through as well), but libevent comes with
an example program.
> Signals are probably the most complex and difficult to understand concept in
> Unix, and understanding how to safely use them is even more difficult. I
> suggest you find a copy of Richard Stevens' Advanced Programming in the UNIX
> Environment.
>
> If Knuth and Stevens have (had) one thing in common, it's that no engineer
> would ever question why you one of their books sat on your book shelf.
I know, and I used to own them both, but the former was hijacked by my
oldest son, and the latter just magically disappeared from my bookshelf...
Thanks,
Ron
> _______________________________________________
> Libevent-users mailing list
> Libevent-users at monkey.org
> http://monkeymail.org/mailman/listinfo/libevent-users
--
NeoNova BV, The Netherlands
Professional internet and VoIP solutions
http://www.neonova.nl Kruislaan 419 1098 VA Amsterdam
info: 020-5628292 servicedesk: 020-5628292 fax: 020-5628291
KvK Amsterdam 34151241
The following disclaimer applies to this email:
http://www.neonova.nl/maildisclaimer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3295 bytes
Desc: S/MIME Cryptographic Signature
Url : http://monkeymail.org/archives/libevent-users/attachments/20080122/822f13eb/smime.bin
More information about the Libevent-users
mailing list