Skip to content

Instantly share code, notes, and snippets.

@artifactsauce
Created October 20, 2011 07:02
Show Gist options
  • Save artifactsauce/1300587 to your computer and use it in GitHub Desktop.
Save artifactsauce/1300587 to your computer and use it in GitHub Desktop.
Perl Parallel::ForkManager
#!/usr/bin/env perl
use strict;
use warnings;
use IPC::Shareable;
use Parallel::ForkManager;
my $process_num = 4;
my $handle = tie( my %result, 'IPC::Shareable', undef, { destroy => 1 } );
my $pm = Parallel::ForkManager->new( $process_num );
my @all_data = qw( one two three );
for my $i ( @all_data ) {
$pm->start and next;
$handle->shlock;
$result{ $i } = calc( $i );
$handle->shunlock;
$pm->finish;
}
$pm->wait_all_children;
sub calc {}
@anopperl
Copy link

nice ..

but
will i have to share key as a $j .....like $result{$j}
?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment