diff options
-rw-r--r-- | ext/Thread/Thread.xs | 6 | ||||
-rwxr-xr-x | t/lib/thread.t | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/ext/Thread/Thread.xs b/ext/Thread/Thread.xs index 543ecf00cf..c3b468314a 100644 --- a/ext/Thread/Thread.xs +++ b/ext/Thread/Thread.xs @@ -238,6 +238,11 @@ newthread (SV *startsv, AV *initargs, char *classname) savethread = thr; thr = new_struct_thread(thr); + /* temporarily pretend to be the child thread in case the + * XPUSHs() below want to grow the child's stack. This is + * safe, since the other thread is not yet created, and we + * are the only ones who know about it */ + SET_THR(thr); SPAGAIN; DEBUG_S(PerlIO_printf(PerlIO_stderr(), "%p: newthread (%p), tid is %u, preparing stack\n", @@ -251,6 +256,7 @@ newthread (SV *startsv, AV *initargs, char *classname) PUTBACK; /* On your marks... */ + SET_THR(savethread); MUTEX_LOCK(&thr->mutex); #ifdef THREAD_CREATE diff --git a/t/lib/thread.t b/t/lib/thread.t index 61997cfc8b..5cc2eaf886 100755 --- a/t/lib/thread.t +++ b/t/lib/thread.t @@ -24,7 +24,7 @@ sub content } # create a thread passing args and immedaietly wait for it. -my $t = new Thread \&content,("ok 2\n","ok 3\n"); +my $t = new Thread \&content,("ok 2\n","ok 3\n", 1..1000); print $t->join; # check that lock works ... |