in reply to Code brewing for the upcoming MCE 10 year anniversary
I completed usability testing,... The following is a demonstration running MCE in the foreground and background. The spawn keyword is also used for spinning a child process per each element.
use MCE::Simple -strict, ( spawn_limit => 2, # MCE::Child processes max_workers => 2, # number of MCE workers init_relay => 1, # define to enable MCE::relay ); # Run MCE in the foreground. mce_foreach my $i (10..18) { MCE::relay { # output orderly say "$$: $i"; }; } # Run MCE in the background. spawn sub { mce_foreach my $i (20..28) { MCE::relay { say "$$: $i"; }; } }; sync; # Spin a worker per each input element. # Up to "spawn_limit" will run simultaneously. # Blocking otherwise, until next availability. spawn my $i (30..38) { say "$$: $i"; } sync;
output:
60264: 10 # alternating PIDs 60265: 11 # two MCE workers 60264: 12 60265: 13 60264: 14 60265: 15 60264: 16 60265: 17 60264: 18 60267: 20 # alternating PIDs 60268: 21 # two MCE workers 60267: 22 60268: 23 60267: 24 60268: 25 60267: 26 60268: 27 60267: 28 60269: 30 # spawn keyword 60270: 31 # unique PIDs 60271: 32 60272: 33 60273: 34 60274: 35 60275: 36 60276: 37 60277: 38
spawn keyword:
spawn my $i (30..38) { say "$$: $i"; } # filtered/transposed to this, without altering line no. foreach my $i (30..38) { MCE::Simple::_spawn_a('', sub { say "$$: $i"; }); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Code brewing for the upcoming MCE 10 year anniversary
by marioroy (Prior) on Nov 11, 2022 at 12:15 UTC | |
by 1nickt (Canon) on Nov 11, 2022 at 13:04 UTC | |
by marioroy (Prior) on Nov 11, 2022 at 13:22 UTC |