Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Enlighten by Abigail-II's example. Tis a MCE::Hobo demonstration.

by marioroy (Prior)
on Mar 14, 2017 at 08:22 UTC ( [id://1184520]=note: print w/replies, xml ) Need Help??


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.

  • Comment on Re^2: Enlighten by Abigail-II's example. Tis a MCE::Hobo demonstration.
  • Download Code

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

    MCE::Shared 1.817 has been released. The reason is to have MCE::Hobo run consistenly on all platforms including Windows. From 1.817 onwards, MCE::Hobo will spawn a process via fork on Windows, similar to running on any Unix OS.

    use strict; use warnings; use MCE::Hobo; use Time::HiRes 'time'; 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 = 3e7; $x-- while $x; print "$$\n"; }); printf "Seconds: %0.03f\n", time - $start;
      From 1.817 onwards, MCE::Hobo will spawn a process via fork on Windows,

      Really? That's a clever trick given Windows doesn't do fork!? Or do you mean that you are now using Perl's thread-based fork-emulation rather then the threads apis directly?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Hi BrowserUk. Yes, MCE::Hobo 1.817 onwards is using Perl's thread-based fork-emulation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1184520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found