Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:15:08+00:00 2026-05-16T07:15:08+00:00

I have a few blocks of code, inside a function of some object, that

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:15:08+00:00Added an answer on May 16, 2026 at 7:15 am

    I haven’t seen subs::parallel before, but given that it’s doing all of the thread handling for you, and it seems to be doing it wrong, based on the error message, I think it’s a bit suspect.

    Normally I wouldn’t just suggest throwing it out like that, but what you’re doing really isn’t any harder with the plain threads interface, so why not give that a shot, and simplify the problem a bit? At the same time, I’ll give you an answer to the other part of your question.

    use threads;
    my @jobs;
    push @jobs, threads->create(sub {
      # do some work
    });
    
    push @jobs, threads->create(sub {
      # do some other work
    });
    
    # Repeat as necessary :)
    
    $_->join for @jobs; # Wait for everything to finish.
    

    You need something a little bit more intricate if you’re using the return values from those subs (simply switching to a hash would help a good deal) but in the code sample you provided, you’re ignoring them, which makes things easy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that roughly does this inside of a GAE worker task:
We have a few places where we include inline <script> blocks which run code,
I have to fix some existing code that builds just fine with LLVM (on
i have few confusion regarding ORM(Object Relational Mapping) i am thinking about to use
I have few graphic effects on image which i am able to run on
I'm compiling using Code::Blocks on Windows 7 using the MinGW compiler (which I can
I have some html code, so: <div class=ui-tabs-panel> <div class=dataTables_wrapper> <div> <button>Add Whatever</button> </div>
I just have a few general questions about keeping code clean and readable. 1)
I have a few dynamically loaded images, with width and height being set inside
I have few sets of code to display right side of my webpage. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.