anlamarama has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to integrate IPC::Shareable module to Parallel::Forkmanager module, but having troubles with global variables.
I have developed a proof of concept script for myself to see how IPC::Shareable is actually working.
use Parallel::ForkManager; use IPC::Shareable; my $pm = new Parallel::ForkManager(10); my %options = ( create => 1, exclusive => 0, mode => 0644, destroy => 1, ); my $testvr = 0; tie $testvr, 'IPC::Shareable', 'data', \%options; for(my $i = 0; $i < 100; $i++) { $pm->start and next; (tied $testvr)->shlock; $testvr++; (tied $testvr)->shunlock; print $testvr . "\n"; $pm->finish; } $pm->wait_all_children;
This script works as intended, but when I try to modify $testvr variable inside for loop, it is not working correctly. What should I do to fix this issue? Any ideas?
Example:
for(my $i = 0; $i < 100; $i++) { $pm->start and next; if($testvr >= 5) { $testvr = 0; } (tied $testvr)->shlock; $testvr++; (tied $testvr)->shunlock; print $testvr . "\n"; $pm->finish; } $pm->wait_all_children;
The output should be:
1(locking variable inside if statement is not working)
I am sure I am missing something obvious but could not find solution.
Thanks in advance,
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: IPC::Shareable and Parallel::Forkmanager Question
by spx2 (Deacon) on Nov 03, 2009 at 14:18 UTC | |
by anlamarama (Acolyte) on Nov 03, 2009 at 20:20 UTC | |
Re: IPC::Shareable and Parallel::Forkmanager Question
by BioLion (Curate) on Nov 03, 2009 at 21:09 UTC | |
by anlamarama (Acolyte) on Nov 03, 2009 at 21:21 UTC |