To be honest, I usually design with shared deep hashes, so I never have to bother with locking. I make a shared variable for each thread, so each thread's shared variable is for it only.

This isn't the case in the chat server I showed, and I'm sure the purists out there, will say to use locking, etc, but that would only be needed if you were using a single shared variable being written to by multiple threads. In the chat server case, all they are doing is removing themselves from the shared array. It would be different if they could remove ANY thread from the array. Also, I was given this same comment from a threads guru, who was perplexed why locking wasn't needed, and he guessed that there is some low-level locking occurring because, in threads, the execution pointer can only be at one place at a time. BUT, KNOCK ON WOOD :-) Possibly an error may occur every million runs, but it seems to run fine for me. But add locking if you want, it won't hurt if done correctly.

I hope you are not the bearer of bad news, forewarning me of the need to lock. :-)


I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re^3: How to pass client connections to the worker threads? by zentara
in thread How to pass client connections to the worker threads? by sunshine_august

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.