From: Elizabeth Mattijsen <liz@dijkmat.nl>
Date: Fri, 12 Jul 2002 00:27:53 +0000 (+0200)
Subject: Re: Thread object by tid?
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c9849ff798160d7f115286b222762e1c4e65f66;p=p5sagit%2Fp5-mst-13.2.git

Re: Thread object by tid?
Message-Id: <4.2.0.58.20020712002638.0218ce10@mickey.dijkmat.nl>

p4raw-id: //depot/perl@17499
---

diff --git a/ext/threads/threads.pm b/ext/threads/threads.pm
index 6ad724e..86f8766 100755
--- a/ext/threads/threads.pm
+++ b/ext/threads/threads.pm
@@ -65,6 +65,14 @@ sub async (&;@) {
     return threads->new($cref,@_);
 }
 
+sub object {
+    return undef unless @_ > 1;
+    foreach (threads->list) {
+        return $_ if $_->tid == $_[1];
+    }
+    return undef;
+}
+
 $threads::threads = 1;
 
 bootstrap threads $VERSION;
@@ -97,6 +105,7 @@ threads - Perl extension allowing use of interpreter based threads from perl
     $thread->detach();
 
     $thread = threads->self();
+    $thread = threads->object( $tid );
 
     $thread->tid();
     threads->tid();
@@ -166,6 +175,12 @@ new thread that's created.
 NB the class method C<< threads->tid() >> is a quick way to get the
 current thread id if you don't have your thread object handy.
 
+=item threads->object( tid )
+
+This will return the thread object for the thread associated with the
+specified tid.  Returns undef if there is no thread associated with the tid
+or no tid is specified or the specified tid is undef.
+
 =item threads->yield();
 
 This is a suggestion to the OS to let this thread yield CPU time to other