punit jain wrote:
Hi,

Hello,

I am facing an issue. Below is code snippet : -

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;

Here you are creating a variable named $count which is only visible inside the scope of this subroutine, so your other $count variable is not affected.


                                }

                }



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to