in reply to Re: Enlighten by Abigail-II's example. Tis a MCE::Hobo demonstration.
in thread Enlighten by Abigail-II's example. Tis a MCE::Hobo demonstration.
A while back, MCE::Hobo spawned children on the Windows platform until recently, now threads. Hence, one might want the thread-id in the output. There is no "wait" equivalent for threads. Therefore, MCE::Hobo->waitone is not yet optimized on Windows. Other MCE::Hobo methods are fine.
use strict; use warnings; use if $^O eq 'MSWin32', 'threads'; use Time::HiRes 'time'; use MCE::Hobo; my $tid = 0; sub CLONE { $tid = threads->tid() if $INC{'threads.pm'}; } sub mhobo ($$&) { my ($count, $max, $code) = @_; foreach my $c (1 .. $count) { MCE::Hobo->waitone() unless $c <= $max; exit(255) unless defined (my $h = MCE::Hobo->create($code, $c) +); } MCE::Hobo->waitall(); } my $start = time; mhobo(12, 4, sub { my $x = 1e8; $x-- while $x; print "$$.$tid\n"; }); printf "Seconds: %0.03f\n", time - $start;
Please know that MCE::Hobo was an exercise for a threads-like or forks-like companion to MCE::Shared.
Regards, Mario.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Enlighten by Abigail-II's example. Tis a MCE::Hobo demonstration.
by marioroy (Prior) on Mar 19, 2017 at 11:37 UTC | |
by BrowserUk (Patriarch) on Mar 19, 2017 at 12:55 UTC | |
by marioroy (Prior) on Mar 19, 2017 at 17:54 UTC |