If you included the full error message (including the line number), I'd have a chance of knowing which thread terminated abnormally.

If you included all the source code, I might stand a chance of trying it out for myself.

If you posted the code without the line numbers, I wouldn't have to strip them off.

And your code would be far easier (for you and me) to read and analyse if it was formatted consistently.

As it is, the most obvious problem is that %clients isn't declared (or shared) anywhere.

And BTW, this %clients = ( %clients, "$client_ip:$client_port" => fileno($client) ) ; is a really horrible way to add a new key/value pair to a hash. A simple:

$clients{ "$client_ip:$client_port" } = fileno($client);

is much easier to read and far more efficient.

You've also failed to do any locking of your shared hash. (Assuming it is actually declared & shared somewhere in the code you've omitted!)


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.
"I'd rather go naked than blow up my ass"

In reply to Re^7: threads with shared variables across multiple instances of a module by BrowserUk
in thread threads with shared variables across multiple instances of a module by fert

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.