#!/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);
阅读(1048) | 评论(0) | 转发(0) |