One question : What is the difference between a thread updating a shared hash and exiting (A) and a thread joining the main process with return data (B).

A couple of thoughts on this.

One of the drawbacks of threads, is that if a thread calls "exit".... it will take down the entire process, all other threads will exit too. I think you mean detach instead of exit.

Secondly, when a thread updates a shared hash, none of the other threads see the update, until they actually try to read it themselves. This is why I like timers so much in the main thread. It can repeatedly loop thru share hashes and update the shared values. As far as I know, there is no tie in shared hashes, that would be a neat feature.

One of the often overlooked aspects of threads, is that in order for a thread to be joined OR detach and dissappear, is that the thread must either

1. reach the end of it's code block or

2. return

So you need to design your threads to finish properly, or they may never join or detach successfully..... they may hang around and give an error like " program exited with 3 threads still running"


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

In reply to Re^10: Should I use threads? Perl/DHCP/Radius by zentara
in thread Should I use threads? Perl/DHCP/Radius by Anonymous Monk

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.