With the join commented out, the main thread (and therefore the entire process) terminates before the slave thread ever gets a timeslice. Therefore Perl never attempts to execute the require and so no error message is produced.

The point here is that the code in the new thread does not get run immediately when you execute the threads->create(). It will not be run until some time later when the OS gets around to allocating it a timeslice. On a single core system this wouldn't happen until the main thread completes its timeslice. On a multi-core system it may get run concurrently with the main thread depending upon the current state of the OS load (including all other processes and system threads). But there is no way to predict how much later that will be.

If you added a sleep to the main thread (at the same position as the commented out join), then you would see the error because the slave thread would get a timeslice while the main thread was sleeping.

But why would you comment out the join?


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.

In reply to Re^3: Why do my threads sometimes die silenty? by BrowserUk
in thread Why do my threads sometimes die silenty? by alain_desilets

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.