summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorDan Sugalski <dan@sidhe.org>2000-10-25 09:36:35 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2000-10-25 20:14:30 +0000
commit8dcd6f7b32c170bcf62c1187a3413da9a3cdf97a (patch)
tree8465bcaf8dd18dc7ab182f0ea73e93049e9c1910 /ext
parent2607bbb4b9732ac518aea01a4967f693eba5de58 (diff)
downloadperl-8dcd6f7b32c170bcf62c1187a3413da9a3cdf97a.tar.gz
Add non-blocking thread doneness checking
Message-Id: <5.0.0.25.0.20001025133504.01ef1e20@24.8.96.48> plus regen global.sym. p4raw-id: //depot/perl@7442
Diffstat (limited to 'ext')
-rw-r--r--ext/Thread/Thread.pm17
-rw-r--r--ext/Thread/Thread.xs9
2 files changed, 26 insertions, 0 deletions
diff --git a/ext/Thread/Thread.pm b/ext/Thread/Thread.pm
index c752e3d6dd..22ae4ef404 100644
--- a/ext/Thread/Thread.pm
+++ b/ext/Thread/Thread.pm
@@ -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
diff --git a/ext/Thread/Thread.xs b/ext/Thread/Thread.xs
index 17e5aefd04..27e2533f3e 100644
--- a/ext/Thread/Thread.xs
+++ b/ext/Thread/Thread.xs
@@ -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: