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; #### 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;