我是线程中的新手,这就是我所做的:
my $thread_fifo = threads->create(sub {Plugins::Fifo->run($conf, $products, $workfifo)});
my $thread_liberty = threads->create(sub {Plugins::Fifo->run($conf, $products, $workliberty)});
然后:$thread_fifo->join(); $thread_liberty->join();
这是错误消息:
Thread 1 terminated abnormally: Can't call method "getChildrenByTagNameNS" on unblessed reference at C:/strawberry/perl/site/lib/XML/Atom/Util.pm line 61.
要查看$thread_fifo
是什么,我使用ref和Dumper:
print ref($thread_fifo); # output : threads
print Dumper($thread_fifo); #output : $VAR1 = bless( do{\(my $o = '78589096')}, 'threads' );
我知道一个未经证实的引用错误是一个变量不是对象的合法引用,但是试图调用它上面的函数就好像它是一个合法的对象,但我不知道这里的问题在哪里,我所要做的就是同时调用两个函数。
提前致谢。
答案 0 :(得分:2)
不是一个完整的解决方案,但应该足以看到最新情况
threads->create(\&foobar,$products,$workfifo,'info');
threads->create(\&foobar,$products,$workliberty,'liberty');
# Master Thread
my @threads = threads->list();
for(my $i=0; $i<scalar(@threads); ++$i) {
print STDERR "MASTER: about to join thread $i\n";
my $thread = $threads[$i];
eval {
$thread->join();
};
if($@) {
print STDERR "Caught error while joining thread $i ($@)\n";
}
else {
print STDERR "MASTER: finished joining thread $i\n";
}
}
@threads = threads->list();
print STDERR "I GOT " . scalar(@threads) . ", NOW EXITING\n";
exit;
# Child threads
sub foobar {
my ($products,$work,$str) = @_;
print STDERR "CHILD $str: STARTING\n";
Plugins::Fifo->run($conf, $products, $work);
print STDERR "CHILD $str: ENDING\n";
}