# https://metacpan.org/pod/PAR::Packer # https://metacpan.org/pod/pp # # pp -o demo.exe demo.pl # ./demo.exe use strict; use warnings; use if $^O eq "MSWin32", "threads"; use if $^O eq "MSWin32", "threads::shared"; # Include minimum dependencies for MCE::Hobo. # Add other modules required by your application here. use Storable (); use Time::HiRes (); # use IO::FDPass (); # optional: for condvar, handle, queue # use Sereal (); # optional: for faster serialization use MCE::Hobo; use MCE::Shared; # For PAR to work on the Windows platform, one must include manually # any shared modules used by the application. # use MCE::Shared::Array; # for MCE::Shared->array # use MCE::Shared::Cache; # for MCE::Shared->cache # use MCE::Shared::Condvar; # for MCE::Shared->condvar # use MCE::Shared::Handle; # for MCE::Shared->handle, mce_open # use MCE::Shared::Hash; # for MCE::Shared->hash # use MCE::Shared::Minidb; # for MCE::Shared->minidb # use MCE::Shared::Ordhash; # for MCE::Shared->ordhash # use MCE::Shared::Queue; # for MCE::Shared->queue # use MCE::Shared::Scalar; # for MCE::Shared->scalar # Et cetera. Only load modules needed for your application. use MCE::Shared::Sequence; # for MCE::Shared->sequence my $seq = MCE::Shared->sequence( 1, 9 ); sub task { my ( $id ) = @_; while ( defined ( my $num = $seq->next() ) ) { print "$id: $num\n"; sleep 1; } } sub main { MCE::Hobo->new( \&task, $_ ) for 1 .. 3; MCE::Hobo->waitall(); } # Main must run inside a thread on the Windows platform or workers # will fail duing exiting, causing the exe to crash. The reason is # that PAR or a dependency isn't multi-process safe. ( $^O eq "MSWin32" ) ? threads->create(\&main)->join() : main(); threads->exit(0) if $INC{"threads.pm"};