Sorry, you're right. How did we miss that. How's this?

#! perl -slw use 5.010; use strict; use threads; =commant sub_1 can run immediately sub_2 can run immediately sub_3 can run only after sub_1 finishes sub_4 can run only after sub_1 finishes sub_5 can run only after sub_2 finishes sub_6 can run only after sub_2 finishes sub_7 can run only after both sub_1 and sub_2 finish sub_8 can run only after both sub_1 and sub_2 finish =cut sub sub1 { say"sub1 starts"; say("sub1:$_"),sleep 1 for 1..3; say"sub1 + ends" } sub sub2 { say"sub2 starts"; say("sub2:$_"),sleep 1 for 1..3; say"sub2 + ends" } sub sub3 { say"sub3 starts"; say("sub3:$_"),sleep 1 for 1..3; say"sub3 + ends" } sub sub4 { say"sub4 starts"; say("sub4:$_"),sleep 1 for 1..3; say"sub4 + ends" } sub sub5 { say"sub5 starts"; say("sub5:$_"),sleep 1 for 1..3; say"sub5 + ends" } sub sub6 { say"sub6 starts"; say("sub6:$_"),sleep 1 for 1..3; say"sub6 + ends" } sub sub7 { say"sub7 starts"; say("sub7:$_"),sleep 1 for 1..3; say"sub7 + ends" } sub sub8 { say"sub8 starts"; say("sub8:$_"),sleep 1 for 1..3; say"sub8 + ends" } my $t1 = async{ sub1(); return async { my $t = async { sub3(); }; sub4(); $t->join; }; }; my $t2 = async{ sub2(); return async { my $t = async{ sub5(); }; sub6(); $t->join }; }; my @kids; push @kids, $_->join for $t1, $t2; push @kids, async{ sub7() }; sub8(); $_->join for @kids; print "main ends"; __END__ c:\test>854022.pl sub1 starts sub1:1 sub2 starts sub2:1 sub1:2 sub2:2 sub1:3 sub2:3 sub1 ends sub2 ends sub4 starts sub3 starts sub3:1 sub4:1 sub6 starts sub5 starts sub6:1 sub5:1 sub8 starts sub8:1 sub7 starts sub7:1 sub3:2 sub4:2 sub5:2 sub6:2 sub8:2 sub7:2 sub3:3 sub4:3 sub5:3 sub6:3 sub8:3 sub7:3 sub3 ends sub4 ends sub5 ends sub6 ends sub8 ends sub7 ends main ends

In reply to Re^5: multithreads newbie question by BrowserUk
in thread multithreads newbie question by daverave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.