Hi Punit, On Mon, 30 Jul 2012 19:17:21 +0530 punit jain <contactpunitj...@gmail.com> wrote:
> Hi, > > > I am facing an issue. Below is code snippet : - > It is a good idea to include a self-contained reproducing code that will demonstrate the problem - not incomplete snippets. > my $pm = new Parallel::ForkManager(10); > > my $count=0; > > foreach my $user (@users) { > > $pm->start($user) and next; > > my $result; > > --- do some processing --- > > $pm->finish(0, \$result); > > } > > > > $pm->wait_all_children; > > > However the final value of count is not correct. Is there some race > condition on same variable updation by the processes ? > > Regards, > Punit > > > > pm -> run_on_finish ( > > sub { > > my $result = @; > > if (defined($result)) { > > my $count += $result; > This is wrong - $count will be a lexical variable only present inside its scope. You should declare it global to the scope - outside the anonymous subroutine: <<< my $count = 0; $pm->run_on_finish( sub { $count += $result; } ); >>> For more information see: http://perl.plover.com/FAQs/Namespaces.html Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Freecell Solver - http://fc-solve.shlomifish.org/ I’d do Windows-- , but this may result in an integer underflow. — an Israeli Linuxer. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/