If you had 3 non-Perl threads, then you could share your Net::Telnet object between the threads so long as only one thread was allowed to access it at a time. Three Perl threads means 3 separate instances of the Perl interpreter. Which means sharing between them involves making 3 copies of every piece of the object. threads::shared knows how to do that for simple data. It can't just do it automatically for you in the case of things containing file handles.

You should be able to work around this limitation if you do your own locking to prevent simultaneous access and take steps to prevent problems from multiple copies each trying to tear down the file handle... if the module doesn't leak state outside of the object. For example, using buffered I/O would leak information into the per-interpreter buffer. Or storing some state information in an (unshared) class-global structure would be a problem.

So, you'd have to inspect the guts of the object to figure out where the file handle is stored. Remove the file handle before calling shared_clone(). Share the fileno of that handle. In each thread, put a clone of the file handle back via something like:

open my $clone, '+<&=', $fileno or die ...;

- tye        


In reply to Re: How do you share an object(Telnet Session) between threads? (clone handle) by tye
in thread How do you share an object(Telnet Session) between threads? by jmlynesjr

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.