Change 29810 by [EMAIL PROTECTED] on 2007/01/14 23:58:49

        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.

Affected files ...

... //depot/perl/ext/threads/threads.xs#135 edit

Differences ...

==== //depot/perl/ext/threads/threads.xs#135 (xtext) ====
Index: perl/ext/threads/threads.xs
--- perl/ext/threads/threads.xs#134~29805~      2007-01-14 04:43:39.000000000 
-0800
+++ perl/ext/threads/threads.xs 2007-01-14 15:58:49.000000000 -0800
@@ -221,10 +221,6 @@
     }
 #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 @@
         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 */
 
End of Patch.

Reply via email to