sweepy838:

No, it's working as it should. The sample provided by zentara simply doesn't show it to you, as each loop runs too fast to allow the next thread to start before it terminates. Uncomment the select statement inside the for loop, and you'll see that they can all run side-by-side. (I'm guessing he forgot to uncomment it before posting.)

$ perl 968307.pl hello 1 from main hello 2 from main hello 3 from main hello 4 from main hello 5 from main hello 6 from main hello 7 from main hello 8 from main hello 9 from main hello 10 from main hello 1 from thread 1 hello 1 from thread 2 hello 1 from thread 3 hello 1 from thread 4 hello 1 from thread 5 hello 1 from thread 6 hello 1 from thread 7 hello 1 from thread 8 hello 1 from thread 9 all done, press the Enter key to exit hello 1 from thread 10 hello 2 from thread 1 hello 2 from thread 2 hello 2 from thread 3 hello 2 from thread 4 hello 2 from thread 5 hello 2 from thread 6 hello 2 from thread 7

Update: Swapped a couple of sentences so it makes more sense.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re^3: multithreading sample needed by roboticus
in thread multithreading sample needed by sweepy838

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.