perl5ever has asked for the wisdom of the Perl Monks concerning the following question:

I just found DJB's page on the "self-pipe trick" for safely mixing signals with select(): http://cr.yp.to/docs/selfpipe.html

Question: Is this trick necessary when using perl's select?
I suppose it would depend on the OS being used.

Replies are listed 'Best First'.
Re: "self-pipe trick" needed with perl?
by ikegami (Patriarch) on Jun 07, 2011 at 19:37 UTC

    It seems to say that it's possible for select not to return (with EINTR or otherwise) on SIGCHLD. If that's true, then yes, it affects Perl. Keep in mind the reference was written in 1992, a lifetime ago, so it may no longer apply.

    Note that the self-pipe trick won't work in Perl (when using safe signals). The signal handler can't cause select to return because the signal handler only get executed after select returns.

      Does/could perl use pselect instead of select where it is available?

        The man page for select/pselect provides more info than your original link.

        Suppose the signal handler sets a global flag and returns. Then a test of this global flag followed by a call of select() could hang indefinitely if the signal arrived just after the test but just before the call.

        This is exactly what Perl does.

        By contrast, pselect() allows one to first block signals, handle the signals that have come in, then call pselect() with the desired sigmask, avoiding the race.

        Perl could do this. It could even use the self-pipe trick internally on systems that don't have pselect.

        My machine supports pselect based on the presence of its man page, but strace shows neither pselect nor a pipe.

        Feel free to submit a bug report.