jasonk, you are a little bit wrong about Anonymous Monk's code, although his code has problem, but not exactly as you pointed out.

First play with two pieces od demos I created:
use threads; use threads::shared; use strict; my $a : shared = 1; { #our $a = 2; print $a; }
And this one:
use threads; use threads::shared; use strict; my $a : shared = 1; threads->create(\&display); <STDIN>; sub display { #our $a = 2; print $a; }


Try to play with that line I commented out, try to comment it and uncomment it, see what you would get.
  1. If you comment out that line (doesn't matter which version of my demo, the one with two threads, or the one with actually one thread), you would get 1, because $a refers to the shared variable, and its value is 1.
  2. If you uncomment that line, you would get 2, because now $a refers to our $a.
Now let's carefully examine Anonymous Monk's code together. You can see that, before he call accept(), he actually declared $client in the same scope, and passed the newly accepted socket to his start_thread function, so he does stored multiple connections.

However, in his begin function, he used the shared $client, which is not initialized.

More important, we should look at this from a conceptual view, not focus on his code too much (his code has some bugs, but that does not mean that what in his mind is wrong.)

From a conceptual view, as I said in my original reply, to share socket among threads will not be a problem for Perl, and it should be shared just like any other object. Just wait for bless to be fixed.


In reply to Re: Re: Re: sharing variables with threads by pg
in thread sharing variables with threads 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.