Created
October 20, 2011 07:02
-
-
Save artifactsauce/1300587 to your computer and use it in GitHub Desktop.
Perl Parallel::ForkManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice ..
but
will i have to share key as a $j .....like $result{$j}
?