我尝试在Windows Perl中使用AnyEvent的fork_call。我写了一些示例代码:
use AnyEvent;
use AnyEvent::Util;
use Data::Dumper;
my $cv = AnyEvent -> condvar;
my $a;
fork_call {
$a = 1;
$cv -> send;
}, sub {
$cv -> recv;
print Dumper $a;
}
但我收到了以下错误:
Can't locate object method "one_event" via package "AnyEvent" at
C:/Perl/perl/site/lib/AnyEvent/Util.pm line 329.
END failed--call queue aborted.
答案 0 :(得分:1)
你的代码错了。如果您使用fork()
,那么您将拥有$cv
和$a
的副本。正确的代码是:
use AnyEvent;
use AnyEvent::Util;
my $cv = AnyEvent->condvar;
my $a;
fork_call {
1;
} sub {
($a) = @_;
print($a);
$cv->send();
};
$cv->wait();