From 46c5d8f143a90fd1492462389f22a61a11e6931c Mon Sep 17 00:00:00 2001 From: Dave Mitchell Date: Sun, 14 Jan 2007 23:58:49 +0000 Subject: [PATCH] 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 --- ext/threads/threads.xs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ext/threads/threads.xs b/ext/threads/threads.xs index 4fc60db..80671ee 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 */ -- 1.8.3.1