#!/usr/bin/perl
use strict;
use warnings;
use Data::Dump qw(dump);
use Perl6::Say;
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;
say dump(@data);
阅读(1122) | 评论(0) | 转发(0) |