+ -
当前位置:首页 → 问答吧 → Perl 获取线程的返回值

Perl 获取线程的返回值

时间:2010-12-24

来源:互联网

我有这样的需求:在一个函数中开一个线程,让这个线程的返回值输出出来,又想让这个线程自动的结束。
请问该怎么办?
比如,我想在执行acceptFileTransfer 的时候,开启线程后,立即返回,然而又想让线程函数execFromCmdLine的返回值打印出来。
sub acceptFileTransfer {
my ($self, $action) = @_;

my $cmd = "Sikuli-IDE.exe --args BT_ACCEPT_FILE_TRANSFER -s -r $sikuli";
my $thr = threads->create( "execFromCmdLine", ($cmd) );
$thr->yield() if (defined $thr); 
$thr->detach() if (defined $thr);

#my $result = $thr->join();
#INFO "************* thread for acceptFileTranfer return value *************";
#INFO "$result\n";

return 1;
}

作者: liujunyu   发布时间: 2010-12-24

线程共享,这个怎么弄都行吧。比如用queue。另外join有问题吗?

作者: iambic   发布时间: 2010-12-24