Since you seem to be learning threads....I'll "pound in" the basic lesson, which seems to elude most thread programmers, until they "learn by experience".

In addition to the comment,by BrowserUk,about your "endless loop" in a thread, a thread will NOT return until it gets to the end of it's code block. It is mentioned in the docs for threads, but it isn't emphasized enough, and most programmers don't "absorb it's meaning" until they run into the warnings.

So whether you detach, or wait to join, that warning will be there when you exit the program. You've noticed that BrowserUk's example uses a "countdown", which assures that the thread code finishes.

You must have a mechanism, thru code design(like countdown or alarm), or some signal sent thru shared variables, to tell the thread to go to the end of it's code block, when finished. Even "sleeping threads" need to have this done, or you will get warnings.

You may even have to catch SIG{INT}, in case you hit control-c, to shutdown the threads before exiting. Like:

$SIG{INT} = sub{ foreach(@threads){$thread_exit{$_} = 1;} };
or do whatever to send all running threads to the end of their code block.

So, repeat 100 times, "a thread must reach the end of it's code block, or there will be warnings (but maybe no harm done).


I'm not really a human, but I play one on earth. flash japh

In reply to Re: Thread detach by zentara
in thread Thread detach by ilanv

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.