假设我有 10 个线程同时运行。当线程完成时有什么方法可以调用某些方法吗?我在想这样的事情:
$thread->onFinish(sub { print "I'm done"; });
最佳答案
您在标题中提出的问题和您在正文中提出的问题不同。
不同线程查明线程是否仍在运行的标准方法是等待它或使用 is_running
和/或 is_joinable
轮询它,具体取决于您的特殊需求。
如果您想要的只是打印i'm done
,那么请确保这是线程主体中执行的最后一条语句,并且它将被打印。
threads->create(sub {
# call the actual routine that does the work
print "i'm finished\n";
});
关于perl - 当 Perl 线程完成其工作时,有什么办法可以做一些事情吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2392835/