This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Mask signals in thread creation and destruction to avoid a segfault
authorJohn Wright <john.wright@hp.com>
Wed, 6 May 2009 21:48:12 +0000 (15:48 -0600)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sun, 7 Jun 2009 12:59:56 +0000 (14:59 +0200)
commitb762d8667351cb765bc1d6419d30acff085da502
tree60c7b76e19aa83fc0fa775d601fbfde884eae3cd
parent01be0729981136a058cce07a897ccdb94609e1c0
Mask signals in thread creation and destruction to avoid a segfault

If our signal handler gets called before a thread got a chance to run
PERL_SET_CONTEXT(), the call to get the thread-specific interpreter will
fail, and we'll end up with aTHX == NULL.  Prevent this from happening
by blocking most signals right before creating the new thread.  This
way, the new thread starts out with most signals blocked, and it
unblocks them when it's ready to handle them.

This required saving the original signal mask somewhere - I put it in
the thread struct.

In several places, PERL_SET_CONTEXT() is called before the target perl
interpreter struct has been fully initialized, so this patch adds code
to block signals around those blocks of code.
ext/threads/threads.xs [changed mode: 0644->0755]