Hola Monks,
I ealier had a question related to threads, where somebody recommend I use forks instead. Another person recommended I use the Parallel::ForkManager module. I got a test script up and running with it, (very easy) but I do not how to get the return values. Please help! :)
#!/usr/bin/perl
#Script to test out the Parallel::ForkManager module
use strict;
use Parallel::ForkManager;
%Test_hash=("A",1,"B",2,"C",3,"D",4);
#Start the Parrel Fork Manager
my $pfm = new Parallel::ForkManager($max_threads);
# Setup a callback for when a child finishes up so we can
# get it's exit code
$pfm->run_on_finish(
sub {
my ($pid, $exit_code, $ident) = @_;
print $pid . "\n";
# print "** $ident just got out of the pool ".
# "with PID $pid and exit code: $exit_code\n";
}
);
my $line="";
my $child="";
my %Values=();
foreach $line(keys %Test_hash)
{
# Forks and returns the pid for the child:
my $pid = $pfm->start($line) and next;
$Values{$pid}=&Test_fork($line, $Test_hash{$line});
$pfm->finish($child); # Terminates the child proces
}
sub Test_function
{
my ($a,$b)=@_
my $c = $a * $b;
return $c;
}
How do I get the return values of the Subfunction I fork off?? In the $pfm->run_on_finish section??
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.