title: simple parallel processing in perl
body: <p>I have a few blocks of code, inside a function of some object, that can run in parallel and speed things up for me.</p>
  
  <p>I tried using <code>subs::parallel</code> in the following way (all of this is in a body of a function):</p>
  
  <pre><code>my $is_a_done = parallelize { 
                                # block a, do some work
                                return 1;
                               };
  my $is_b_done = parallelize { 
                                # block b, do some work
                                return 1;
                               };
  my $is_c_done = parallelize { 
                                # block c depends on a so let's wait (block)
                                if ($is_a_done) {
                                 # do some work
                                };
                                return 1;
                               };
  my $is_d_done = parallelize { 
                                # block d, do some work
                                return 1;
                               };
  
  if ($is_a_done &amp;&amp; $is_b_done &amp;&amp; $is_c_done &amp;&amp; $is_d_done) {
   # just wait for all to finish before the function returns
  }
  </code></pre>
  
  <p>First, notice I use <code>if</code> to wait for threads to block and wait for previous thread to finish when it's needed (a better idea? the <code>if</code> is quite ugly...).</p>
  
  <p>Second, I get an error:</p>
  
  <pre><code>Thread already joined at /usr/local/share/perl/5.10.1/subs/parallel.pm line 259.
  Perl exited with active threads:
      1 running and unjoined
      -1 finished and unjoined
      3 running and detached
  </code></pre>