use strict; use warnings; use MCE::Hobo; use MCE::Inbox; ## # MCE::Inbox is not yet released on MetaCPAN. It can be used with any # parallel module of choice to include threads. # # Specify mailbox names during construction. Behind the scene, # makes a MCE::Shared->queue object per mailbox. ## my $inbox = MCE::Inbox->new('mngrbox', 'donebox'); MCE::Hobo->init( posix_exit => 1 ); # Workers mce_async { sleep 5; $inbox->send('mngrbox', { ident => 'id1', key => 'value1' }); # do other work, perhaps more send('mngrbox', ...) $inbox->send('donebox', 1); }; mce_async { sleep 1; $inbox->send('mngrbox', { ident => 'id2', key => 'value2' }); # do other work, perhaps another send('mngrbox', ...) $inbox->send('donebox', 1); }; mce_async { $inbox->send('mngrbox', { ident => 'id3', key => 'value3' }); # do other work, perhaps send('mngrbox', ...) in a loop $inbox->send('donebox', 1); }; # Manager while ( my $ret = $inbox->recv('mngrbox') ) { printf "ident: %s, key: %s\n", $ret->{ident}, $ret->{key}; MCE::Hobo->waitone if $inbox->recv_nb('donebox'); # non blocking last unless MCE::Hobo->pending; }