Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Why do my threads sometimes die silenty?

by alain_desilets (Beadle)
on Sep 21, 2011 at 21:22 UTC ( #927234=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Why do my threads sometimes die silenty?
in thread Why do my threads sometimes die silenty?

Here is an example that more closely approximate my app's situation:

use strict; use threads; use threads::shared; use Thread::Pool; my $signal = undef; share($signal); my $fct = sub { require Blah; Blah->import(); $signal = 1; }; print "Starting the Thread::Pool\n"; my $pool = Thread::Pool->new( {do => $fct}); print "Thread::Pool started\n"; print "Sending a job to the Thread::Pool\n"; $pool->job(); print "Job sent to the Thread::Pool\n"; print "Waiting for the slave thread to set the shared signal\n"; while (!$signal) { print "Sleeping and waiting for signal from slave thread\n"; sleep(1); } print "Got shared signal from slave thread\n"; $pool->shutdown();
When I run it, I get:
Starting the Thread::Pool
And it gets stuck there, without outputting any error message. Obviously here, the slave gets a slice of CPU, since I sleep for 1 second between polls of the shared signal.

Note that if I coment out the faulty require line, I do get the proper behaviour, i.e. the script prints:
Starting the Thread::Pool Thread::Pool started Sending a job to the Thread::Pool Job sent to the Thread::Pool Waiting for the slave thread to set the shared signal Sleeping and waiting for signal from slave thread Got shared signal from slave thread


Comment on Re^5: Why do my threads sometimes die silenty?
Select or Download Code
Re^6: Why do my threads sometimes die silenty?
by BrowserUk (Pope) on Sep 21, 2011 at 21:33 UTC

    What happens (*) if you change this:

    my $signal = undef; share($signal);

    To: my $signal :shared; ?

    I can't test it as I don't have Thread::Pool. It isn't available as a PPM for my version of Perl and I cannot be bothered to try and track down the numerous crappy, bloated dependencies it has to install it manually, given that I would never use it.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Changed the $signal declaration to my $signal :shared; as you suggested, and I get the same behaviour as before. The thread never returns (because of the faulty "use Blah"), but I never see the error message. Alain

        Sorry, but I cannot even begin to see how to debug Thread::Pool. You're best bet would be to raise the problem with the maintainer.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2015-07-01 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (19 votes), past polls