- 论坛徽章:
- 0
|
自己看了看文档,实现了一个子线程运行完成之后,主进程让子线程退出的方法,示例代码如下:
threads->create(\&run_thread);
threads->create(\&run_thread_15);
while(1) {
my @thrs = threads->list(threads::joinable);
foreach (@thrs) {
$_->join;
print "success join\n";
}
foreach (threads->list) {
print "threads now:", $_, "\n";
}
print "one round end\n";
sleep 5;
}
sub run_thread {
print "thread id is ", threads->tid(), "\n";
sleep 30;
}
sub run_thread_15 {
print "thread id is ", threads->tid(), "\n";
sleep 15;
}
其中关键的一个方法是 threads->list(threads::joinable),可以参见官方文档http://perldoc.perl.org/threads.html |
|