use strict; use warnings; use feature 'say'; use Data::Dumper; ++$Data::Dumper::Sortkeys; use Time::HiRes qw/ usleep time /; use MCE::Shared; use MCE::Loop; my $pid = $$; say "PID $pid"; tie my %hash, 'MCE::Shared', (); $SIG{'INT'} = sub { kill 'TERM', -$$ }; $SIG{'TERM'} = sub { exit 0 }; MCE::Loop->init( max_workers => 6, chunk_size => 10 ); mce_loop { say "Forked child with $$"; my ( $mce, $chunk_ref, $chunk_id ) = @_; for ( @{ $chunk_ref } ) { $hash{ sprintf '%.2d %s', $_, $$ } = time; sleep 1; } } ( 0 .. 99 ); MCE::Loop->finish; END { say sprintf '%s %s (%s) in END', $$, time, $$ == $pid ? 'Parent' : 'Child'; if ( $$ == $pid ) { say 'Parent is ready to dump'; say 'Dumping: ' . Dumper \%hash; } } __END__
Here's an example of the output I am getting from my test program: