I have a few blocks of code, inside a function of some object, that can run in parallel and speed things up for me.
I tried using subs::parallel
in the following way (all of this is in a body of a function):
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 && $is_b_done && $is_c_done && $is_d_done) { # just wait for all to finish before the function returns }
First, notice I use if
to wait for threads to block and wait for previous thread to finish when it's needed (a better idea? the if
is quite ugly...).
Second, I get an error:
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