Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: What is the correct way to finish multithreaded program?

by moritz (Cardinal)
on May 05, 2014 at 08:46 UTC ( #1085017=note: print w/ replies, xml ) Need Help??


in reply to What is the correct way to finish multithreaded program?

While I'm not an expert on threads, I believe this is the problem:

foreach my $thr (@threads) { if ( $thr->is_joinable() ) { $thr->join(); } }

You only join the threads that have already finished; instead you should join them all, i.e. wait for them to finish.


Comment on Re: What is the correct way to finish multithreaded program?
Download Code
Re^2: What is the correct way to finish multithreaded program?
by Gangabass (Priest) on May 05, 2014 at 11:18 UTC
    Hmm... According to docs:
    $thr->is_joinable() Returns true if the thread has finished running, is not detached and has not yet been joined. In other words, the thread is ready to be joined, and a call to $thr->join() will not block.
    Previous block of code (while (..) {..}) used to wait threads to finish (I think). But may be I'm wrong :-(

      Previous block of code (while (..) {..}) used to wait threads to finish (I think). But may be I'm wrong :-(

      Maybe, it depends on more code than shown I think :)

      safest way to wait for threads to finish is to actually wait for them to finish :) blockingly  $_->join for threads->list

        I'm pushing undef into the queue with
        foreach ( 1 .. $config->{number_of_threads} ) { $q->enqueue(undef); }
        and I think this will cause thread to return:
        while ( my $org = $q->dequeue() ) { parse_org( $org, $mech ); $pq->enqueue($org); } say "Finishing worker [$thread_id]"; return;
        Also I have Finishing worker [SOME_ID] in the output...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-09-17 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls