<?xml version="1.0" encoding="windows-1252"?>
<node id="1005465" title="Re: parallel functions" created="2012-11-25 01:26:42" updated="2012-11-25 01:26:42">
<type id="11">
note</type>
<author id="1005295">
marioroy</author>
<data>
<field name="doctext">
&lt;p&gt;A new parallel module was recently added to CPAN called MCE. This is how one could run 2 functions in parallel using MCE.&lt;/p&gt;

&lt;code&gt;
#!/usr/bin/perl
use 5.014;

use MCE;

my $mce = MCE-&gt;new(
   max_workers =&gt; 2,

   user_func =&gt; sub
   {
      my $self = shift;

      if ($self-&gt;wid == 1)
      {
         test1();
      }
      else
      {
         test2();
      }
   }
);

$mce-&gt;run();

sub test1
{
   sleep 3;
   say "in test1";
}

sub test2
{
   sleep 2;
   say "in test2";
}

&lt;/code&gt;

&lt;p&gt;Output&lt;/p&gt;

&lt;code&gt;
in test2
in test1

&lt;/code&gt;</field>
<field name="root_node">
1002746</field>
<field name="parent_node">
1002746</field>
</data>
</node>
