Ugly fix to not die when a thread creator is holding locks.
Artur Bergman [Mon, 29 Oct 2001 12:56:12 +0000 (12:56 +0000)]
p4raw-id: //depot/perl@12755

ext/threads/shared/shared.pm
ext/threads/shared/shared.xs
ext/threads/threads.xs

index 5607186..10d2af9 100644 (file)
@@ -59,7 +59,7 @@ sub CLONE {
     return unless($_[0] eq "threads::shared");
        foreach my $ptr (keys %shared) {
            if($ptr) {
-               thrcnt_inc($shared{$ptr});
+               thrcnt_inc($shared{$ptr},$threads::origthread);
            }
        }
 }
index c00cf15..2eb2e6c 100644 (file)
@@ -171,16 +171,21 @@ _thrcnt(ref)
 
 
 void
-thrcnt_inc(ref)
+thrcnt_inc(ref,perl)
         SV* ref
+       SV* perl
         CODE:
        shared_sv* shared;
+       PerlInterpreter* origperl = (PerlInterpreter*) SvIV(perl);
+       PerlInterpreter* oldperl = PERL_GET_CONTEXT;
         if(SvROK(ref)) 
             ref = SvRV(ref);
         shared = Perl_sharedsv_find(aTHX, ref);
         if(!shared)
            croak("thrcnt can only be used on shared values");
+       PERL_SET_CONTEXT(origperl);
        Perl_sharedsv_thrcnt_inc(aTHX_ shared);
+       PERL_SET_CONTEXT(oldperl);      
 
 void
 _thrcnt_dec(ref)
index a4e22ec..75a6b0b 100755 (executable)
@@ -111,6 +111,11 @@ SV* Perl_thread_create(char* class, SV* init_function, SV* params) {
        init_function = NULL;
        temp_store = NULL;
 
+       temp_store = Perl_get_sv(current_perl, "threads::origthread", TRUE | GV_ADDMULTI);
+       sv_setiv(temp_store,(IV)current_perl);
+       temp_store = NULL;      
+
+       
 #ifdef WIN32
        thread->interp = perl_clone(current_perl, 4);
 #else
@@ -122,6 +127,8 @@ SV* Perl_thread_create(char* class, SV* init_function, SV* params) {
        thread->params = newSVsv(Perl_get_sv(thread->interp,
                                             "threads::paramtempstore",FALSE));
 
+
+
        /*
         * And here we make sure we clean up the data we put in the
         * namespace of iThread, both in the new and the calling