use IPC::Shareable
时间:2010-09-11 来源:snowtty
#!/usr/bin/perl
use Data::Dump qw(dump); use IPC::Shareable;
use Parallel::ForkManager; my $handle = tie my @data, 'IPC::Shareable', undef, { destroy => 1 };
@data = (); my $pm = Parallel::ForkManager->new(10); for my $i (0..100) {
my $pid;
$pid = $pm->start && next;
$handle->shlock;
push(@data, rand($i));
$handle->shunlock;
$pm->finish;
} $pm->wait_all_children; print dump(@data);
use Data::Dump qw(dump); use IPC::Shareable;
use Parallel::ForkManager; my $handle = tie my @data, 'IPC::Shareable', undef, { destroy => 1 };
@data = (); my $pm = Parallel::ForkManager->new(10); for my $i (0..100) {
my $pid;
$pid = $pm->start && next;
$handle->shlock;
push(@data, rand($i));
$handle->shunlock;
$pm->finish;
} $pm->wait_all_children; print dump(@data);
相关阅读 更多 +