in reply to Re: Will Child Threads block the parent thread?
in thread Will Child Threads block the parent thread?

Had I put the join statement in front of the for loop in the main code section, the parent would have waited for the child thread to complete before entering the main for loop

Yikes!!!! I had done just that!!!! I had my "join" statement as soon as I had created the child thread - obviously, Perl waited for the child to finish and only then, it allowed the main program to do its work. I have put the join statement at the end of the code now ... Let's see if that works!

As far as code goes, my code is too huge to put in on this page.. I mean.. many subroutines being used and to make complete sense, I had to put in all of that code here... Just needed to understand the concept, and I realized what I had done wrong...

Btw, are there any other web pages / tutorials / books / chapters that make us understand Threads in Perl in a better way? PerlDoc has very few examples and it's difficult to understand some concepts ... I'm really not very happy with the perldoc help pages.

  • Comment on Re^2: Will Child Threads block the parent thread?

Replies are listed 'Best First'.
Re^3: Will Child Threads block the parent thread?
by BrowserUk (Patriarch) on Feb 27, 2011 at 09:04 UTC
    As far as code goes, my code is too huge to put in on this page.

    I would strongly suggest that you write a few small programs to explore how threading works before starting to use them in large programs. To do otherwise is to almost guarantee that you will create yourself a lot of work and pain trying to get the basics right.


    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.
Re^3: Will Child Threads block the parent thread?
by GrandFather (Saint) on Feb 27, 2011 at 09:39 UTC

    So you had a fundamental problem (join in the wrong place) that you could have demonstrated with 10 - 20 lines of code, and probably have found the problem yourself in the process of generating the sample code. Why would you want to post a ton of cruft just to show that issue (see I know what I mean. Why don't you?)?

    True laziness is hard work
Re^3: Will Child Threads block the parent thread?
by dasgar (Priest) on Feb 27, 2011 at 13:38 UTC
    Btw, are there any other web pages / tutorials / books / chapters that make us understand Threads in Perl in a better way? PerlDoc has very few examples and it's difficult to understand some concepts ... I'm really not very happy with the perldoc help pages.

    I'm personally unaware of other available documentation. That doesn't necessarily mean that they don't exist.

    At times I get confused about the documentation for a new function/module that I'm trying to use. What I usually do is very similar to BrowserUk's suggestion. Just write some small test code to test out the function/module to see if I understand what it is doing and how I'm supposed to use it. Sometimes I personally find that kind of experimentation to be far more useful to me in the learning process than the documentation.

    In fact, even if I think I completely understand the documentation, I'll still do some small experimental code just to verify if I got it right or not. As BrowserUk suggested, it's much easier to debug that small experimental code while trying to learn the new stuff. And once you have figured things out with the small experimentation code, then you're ready to implement it in the real code that you're trying to develop.