Next | 1.2 Thread control methods | Prev |
One thread may explicitely give up CPU to other threads using:
threads->yield;
The thread that created another thread may wait for the child (this operation is blocking unless the child thread is already finished):
Any data that the thread subroutine returns may be accessed in the parent thread:$child_thread->join;
use threads; my $child_thread = threads->new(\&my_function); # ... my @returned_data = $child_thread->join; print "Child thread returned @returned_data"; sub my_function { return "Israel PM", 2003, "September", 11; }
The parent thread may also officially stop to worry about the child using:
$child_thread->detach;
Next | Perl Threads | Prev |