Update Changes.
[p5sagit/p5-mst-13.2.git] / ext / threads / threads.xs
index 2c1f2a5..59e3597 100755 (executable)
@@ -143,7 +143,8 @@ Perl_ithread_hook(pTHX)
     int veto_cleanup = 0;
     MUTEX_LOCK(&create_destruct_mutex);
     if (aTHX == PL_curinterp && active_threads != 1) {
-       Perl_warn(aTHX_ "Cleanup skipped %d active threads", active_threads);
+       Perl_warn(aTHX_ "A thread exited while %" IVdf " other threads were still running",
+                                               (IV)active_threads);
        veto_cleanup = 1;
     }
     MUTEX_UNLOCK(&create_destruct_mutex);
@@ -279,7 +280,7 @@ Perl_ithread_run(void * arg) {
                }
                PUTBACK;
                if (SvTRUE(ERRSV)) {
-                   Perl_warn(aTHX_ "Died:%_",ERRSV);
+                   Perl_warn(aTHX_ "thread failed to start: %" SVf, ERRSV);
                }
                FREETMPS;
                LEAVE;
@@ -287,10 +288,6 @@ Perl_ithread_run(void * arg) {
        }
 
        PerlIO_flush((PerlIO*)NULL);
-       MUTEX_LOCK(&create_destruct_mutex);
-       active_threads--;
-       assert( active_threads >= 0 );
-       MUTEX_UNLOCK(&create_destruct_mutex);
        MUTEX_LOCK(&thread->mutex);
        thread->state |= PERL_ITHR_FINISHED;
 
@@ -300,6 +297,11 @@ Perl_ithread_run(void * arg) {
        } else {
                MUTEX_UNLOCK(&thread->mutex);
        }
+       MUTEX_LOCK(&create_destruct_mutex);
+       active_threads--;
+       assert( active_threads >= 0 );
+       MUTEX_UNLOCK(&create_destruct_mutex);
+
 #ifdef WIN32
        return (DWORD)0;
 #else
@@ -467,7 +469,7 @@ Perl_ithread_CLONE(pTHX_ SV *obj)
   }
  else
   {
-   Perl_warn(aTHX_ "CLONE %_",obj);
+   Perl_warn(aTHX_ "CLONE %" SVf,obj);
   }
 }
 
@@ -515,6 +517,7 @@ Perl_ithread_join(pTHX_ SV *obj)
        /* We have finished with it */
        thread->state |= PERL_ITHR_JOINED;
        MUTEX_UNLOCK(&thread->mutex);
+       sv_unmagic(SvRV(obj),PERL_MAGIC_shared_scalar);
        return retparam;
     }
     return (AV*)NULL;
@@ -599,7 +602,12 @@ PPCODE:
 }
 
 void
-ithread_yield(ithread *thread)
+yield(...)
+CODE:
+{
+    YIELD;
+}
+       
 
 void
 ithread_detach(ithread *thread)