diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2002-01-20 11:50:22 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2002-01-20 11:50:22 +0000 |
commit | ba14dd9ace5a84c9784d70e7ae3b0baccfea783d (patch) | |
tree | 1ba7b457816c5d2b613796ffb7a66192f4748bb8 /ext/threads/threads.xs | |
parent | 4e26b102cfda18e53ed9204623391ff80948c046 (diff) | |
download | perl-ba14dd9ace5a84c9784d70e7ae3b0baccfea783d.tar.gz |
threads work again on Win32. (Not threads::shared yet)
Submit to see if they do on Linux.
p4raw-id: //depot/perlio@14355
Diffstat (limited to 'ext/threads/threads.xs')
-rwxr-xr-x | ext/threads/threads.xs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/ext/threads/threads.xs b/ext/threads/threads.xs index 1b89e2cc14..82989b9edb 100755 --- a/ext/threads/threads.xs +++ b/ext/threads/threads.xs @@ -81,7 +81,6 @@ void Perl_ithread_destruct (pTHX_ ithread* thread) { MUTEX_LOCK(&thread->mutex); - Perl_warn(aTHX_ "destruct %d with count=%d",thread->tid,thread->count); if (thread->count != 0) { MUTEX_UNLOCK(&thread->mutex); return; @@ -102,6 +101,10 @@ Perl_ithread_destruct (pTHX_ ithread* thread) } MUTEX_UNLOCK(&create_mutex); /* Thread is now disowned */ +#if 0 + Perl_warn(aTHX_ "destruct %d @ %p by %p", + thread->tid,thread->interp,aTHX); +#endif if (thread->interp) { dTHXa(thread->interp); PERL_SET_CONTEXT(thread->interp); @@ -129,7 +132,6 @@ ithread_mg_free(pTHX_ SV *sv, MAGIC *mg) { ithread *thread = (ithread *) mg->mg_ptr; MUTEX_LOCK(&thread->mutex); - Perl_warn(aTHX_ "Unmagic %d with count=%d",thread->tid,thread->count); thread->count--; MUTEX_UNLOCK(&thread->mutex); /* This is safe as it re-checks count */ @@ -142,7 +144,6 @@ ithread_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param) { ithread *thread = (ithread *) mg->mg_ptr; MUTEX_LOCK(&thread->mutex); - Perl_warn(aTHX_ "DUP %d with count=%d",thread->tid,thread->count); thread->count++; MUTEX_UNLOCK(&thread->mutex); return 0; @@ -211,7 +212,6 @@ Perl_ithread_run(void * arg) { PerlIO_flush((PerlIO*)NULL); MUTEX_LOCK(&thread->mutex); - Perl_warn(aTHX_ "finished %d with count=%d",thread->tid,thread->count); if (thread->detached == 1) { MUTEX_UNLOCK(&thread->mutex); Perl_ithread_destruct(aTHX_ thread); @@ -233,7 +233,6 @@ ithread_to_SV(pTHX_ SV *obj, ithread *thread, char *classname, bool inc) if (inc) { MUTEX_LOCK(&thread->mutex); thread->count++; - Perl_warn(aTHX_ "SV for %d with count=%d",thread->tid,thread->count); MUTEX_UNLOCK(&thread->mutex); } if (!obj) @@ -297,18 +296,26 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param #else thread->interp = perl_clone(aTHX, CLONEf_KEEP_PTR_TABLE); #endif + /* perl_clone leaves us in new interpreter's context. + As it is tricky to spot implcit aTHX create a new scope + with aTHX matching the context for the duration of + our work for new interpreter. + */ + { + dTHXa(thread->interp); - clone_param.flags = 0; - thread->init_function = Perl_sv_dup(thread->interp, init_function, &clone_param); - if (SvREFCNT(thread->init_function) == 0) { - SvREFCNT_inc(thread->init_function); - } - - thread->params = Perl_sv_dup(thread->interp,params, &clone_param); - SvREFCNT_inc(thread->params); - SvTEMP_off(thread->init_function); - ptr_table_free(PL_ptr_table); - PL_ptr_table = NULL; + clone_param.flags = 0; + thread->init_function = sv_dup(init_function, &clone_param); + if (SvREFCNT(thread->init_function) == 0) { + SvREFCNT_inc(thread->init_function); + } + + thread->params = sv_dup(params, &clone_param); + SvREFCNT_inc(thread->params); + SvTEMP_off(thread->init_function); + ptr_table_free(PL_ptr_table); + PL_ptr_table = NULL; + } PERL_SET_CONTEXT(aTHX); @@ -379,7 +386,6 @@ Perl_ithread_join(pTHX_ SV *obj) { ithread *thread = SV_to_ithread(aTHX_ obj); MUTEX_LOCK(&thread->mutex); - Perl_warn(aTHX_ "joining %d with count=%d",thread->tid,thread->count); if (!thread->detached) { #ifdef WIN32 DWORD waitcode; @@ -392,7 +398,6 @@ Perl_ithread_join(pTHX_ SV *obj) #else pthread_join(thread->thr,&retval); #endif - Perl_warn(aTHX_ "joined %d with count=%d",thread->tid,thread->count); /* We have finished with it */ MUTEX_LOCK(&thread->mutex); thread->detached = 2; @@ -426,7 +431,6 @@ void Perl_ithread_DESTROY(pTHX_ SV *sv) { ithread *thread = SV_to_ithread(aTHX_ sv); - Perl_warn(aTHX_ "DESTROY %d with count=%d",thread->tid,thread->count); sv_unmagic(SvRV(sv),PERL_MAGIC_shared_scalar); } @@ -470,9 +474,6 @@ ithread_detach(ithread *thread) void ithread_DESTROY(SV *thread) -void -ithread_CLONE(SV *sv) - BOOT: { ithread* thread; |