This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add non-blocking thread doneness checking
authorDan Sugalski <dan@sidhe.org>
Wed, 25 Oct 2000 13:36:35 +0000 (09:36 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 25 Oct 2000 20:14:30 +0000 (20:14 +0000)
Message-Id: <5.0.0.25.0.20001025133504.01ef1e20@24.8.96.48>

plus regen global.sym.

p4raw-id: //depot/perl@7442

ext/Thread/Thread.pm
ext/Thread/Thread.xs
global.sym
perl.c
thrdvar.h
util.c

index c752e3d..22ae4ef 100644 (file)
@@ -21,6 +21,11 @@ Thread - manipulate threads in Perl (EXPERIMENTAL, subject to change)
     $result = $t->join;
     $result = $t->eval;
     $t->detach;
+    $flags = $t->flags;
+    
+    if ($t->done) {
+        $t->join;
+    }
 
     if($t->equal($another_thread)) {
        # ...
@@ -29,6 +34,7 @@ Thread - manipulate threads in Perl (EXPERIMENTAL, subject to change)
     my $tid = Thread->self->tid; 
     my $tlist = Thread->list;
 
+
     lock($scalar);
     yield();
 
@@ -181,6 +187,17 @@ increasing integer assigned when a thread is created. The main thread of a
 program will have a tid of zero, while subsequent threads will have tids
 assigned starting with one.
 
+=item flags
+
+The C<flags> method returns the flags for the thread. This is the
+integer value corresponding to the internal flags for the thread, and
+the value man not be all that meaningful to you.
+
+=item done
+
+The C<done> method returns true if the thread you're checking has
+finished, and false otherwise.
+
 =back
 
 =head1 LIMITATIONS
index 17e5aef..27e2533 100644 (file)
@@ -189,6 +189,7 @@ threadstart(void *arg)
     SvREFCNT_dec(PL_lastscream);
     SvREFCNT_dec(PL_defoutgv);
     Safefree(PL_reg_poscache);
+    thr->thr_done = 1;
 
     MUTEX_LOCK(&thr->mutex);
     DEBUG_S(PerlIO_printf(Perl_debug_log,
@@ -448,6 +449,14 @@ flags(t)
 #endif
 
 void
+done(t)
+       Thread  t
+    PPCODE:
+#ifdef USE_THREADS
+     PUSHs(t->thr_done ? &PL_sv_yes : &PL_sv_no);
+#endif
+
+void
 self(classname)
        char *  classname
     PREINIT:
index 0dea03e..2143319 100644 (file)
@@ -465,8 +465,8 @@ Perl_utf8_distance
 Perl_utf8_hop
 Perl_utf8_to_bytes
 Perl_bytes_to_utf8
+Perl_utf8_to_uv_simple
 Perl_utf8_to_uv
-Perl_utf8_to_uv_chk
 Perl_uv_to_utf8
 Perl_warn
 Perl_vwarn
diff --git a/perl.c b/perl.c
index 3d874ca..b65bdb9 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -3637,6 +3637,7 @@ S_init_main_thread(pTHX)
     thr->tid = 0;
     thr->next = thr;
     thr->prev = thr;
+    thr->thr_done = 0;
     MUTEX_UNLOCK(&PL_threads_mutex);
 
 #ifdef HAVE_THREAD_INTERN
index e4cfacc..06cfe72 100644 (file)
--- a/thrdvar.h
+++ b/thrdvar.h
@@ -236,5 +236,5 @@ PERLVAR(i,          struct thread_intern)
 #endif
 
 PERLVAR(trailing_nul,  char)           /* For the sake of thrsv and oursv */
-
+PERLVAR(thr_done,      bool)           /* True when the thread has finished */
 #endif /* USE_THREADS */
diff --git a/util.c b/util.c
index 2122d4e..619c5aa 100644 (file)
--- a/util.c
+++ b/util.c
@@ -3605,6 +3605,7 @@ Perl_new_struct_thread(pTHX_ struct perl_thread *t)
     thr->specific = newAV();
     thr->errsv = newSVpvn("", 0);
     thr->flags = THRf_R_JOINABLE;
+    thr->thr_done = 0;
     MUTEX_INIT(&thr->mutex);
 
     JMPENV_BOOTSTRAP;