summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2007-01-14 23:58:49 +0000
committerDave Mitchell <davem@fdisolutions.com>2007-01-14 23:58:49 +0000
commit46c5d8f143a90fd1492462389f22a61a11e6931c (patch)
tree812bcc044904018228822ee3a23c01882d838a47
parentae3fba3defe4ed89f6b20b720860824178f77f52 (diff)
downloadperl-46c5d8f143a90fd1492462389f22a61a11e6931c.tar.gz
make S_ithread_run() call S_ithread_free() in main context
Fixes a race condition between detach clearing a thread's interpreter, and S_ithread_run() freeing itself while assuming that it's own interpreter still exists. p4raw-id: //depot/perl@29810
-rwxr-xr-xext/threads/threads.xs10
1 files changed, 6 insertions, 4 deletions
diff --git a/ext/threads/threads.xs b/ext/threads/threads.xs
index 4fc60db732..80671ee01c 100755
--- a/ext/threads/threads.xs
+++ b/ext/threads/threads.xs
@@ -221,10 +221,6 @@ S_ithread_free(pTHX_ ithread *thread)
}
#endif
- /* Call PerlMemShared_free() in the context of the "first" interpreter
- * per http://www.nntp.perl.org/group/perl.perl5.porters/110772
- */
- aTHX = MY_POOL.main_thread.interp;
PerlMemShared_free(thread);
/* total_threads >= 1 is used to veto cleanup by the main thread,
@@ -539,6 +535,12 @@ S_ithread_run(void * arg)
my_exit(exit_code);
}
+ /* at this point the interpreter may have been freed, so call
+ * free in the context of of the 'main' interpreter. That can't have
+ * been freed, due to the veto_cleanup mechanism */
+
+ aTHX = MY_POOL.main_thread.interp;
+
MUTEX_LOCK(&thread->mutex);
S_ithread_free(aTHX_ thread); /* releases MUTEX */