Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MCE - Many-Core Engine

  • MCE

  • fork

  • MCE

  • On Debian/Ubuntu it is called libmce-perl

use strict;
use warnings;

use MCE;

main();


sub main {
    my ($workers) = @ARGV;
    die "Usage: $0 WORKERS\n" if not defined $workers;

    my $mce = MCE->new(
        max_workers => $workers,
        user_func => sub {
            my ($mce) = @_;
            $mce->say("Hello from PID $$ WID " . $mce->wid);
        }
     );

    $mce->run;
}


$ perl use_mce.pl 5
Hello from PID 210834 WID 2
Hello from PID 210833 WID 1
Hello from PID 210835 WID 3
Hello from PID 210836 WID 4
Hello from PID 210837 WID 5