The line in question is trying to assign $send_socket to a shared structure. $send_socket is a IO::Socket::INET object. Internally, that is a hash, probably containing other nested data structures.

You would need to share that hash, and everything in it to be able to assign it to a shared hash. You cannot.

There are two reasons for this.

  1. You cannot share a bless reference (object).

    This is because blessing, involves associating (through internal linking (termed "magic")), the data pointed at by that reference with code (the object methods). But Perl cannot run code across threads.

  2. Because if you could share that reference, it would be emptied of it's contents.

    An object without it's instance data is not going to work.

I have seen a reference that says that you can share Perl's object's across threads. The trick (apparently) is to re-bless the (copy of the) object handle available in the (other, non creating) threads where you want to use it.

This is a fine idea, but for it to work, you would first have to deep copy all of the contents of the blessed reference into a previously shared hash. You also have to copy any and all nested data structures referenced from it into new, shared equivalents.

I have tried to do this for some fairly simple objects, but it is very, very, very hard to do at the Perl level. Discovering the structures, and their classes for something as complex as an IO::Handle::INET object would be fraught with problems.

Basically what I am saying is that I cannot do what you are trying to do, and I know of noone who has succeeded in doing it.

If you decide to go ahead and try it anyway, I think that you are very much on your own:

Very few people will even consider trying to render assistance if you tell them that you are trying to share objects between threads. Even fewer will be responsive to bug reports against modules if you tell them you are encountering problems with their modules, when trying to share objects across threads.

I wish it wasn't so, but it is.

Good luck.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re^2: Declaring/Assigning thread shared vars by BrowserUk
in thread Declaring/Assigning thread shared vars 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.