I'm looking for the best way to transmit file/socket/pipe handles between threads. I've been using Storable to communicate jobs to a worker thread (by freezing the job data structure into a shared queue which the thread then pops and thaws it from - is this regarded as Good Practice?), but since Storable can't serialise globs, I can't pass the thread a new IO::Handle to work with.

My first reaction was to try to locally add STORABLE_freeze and STORABLE_thaw methods to IO::Handle, but this doesn't work since IO::Handle objects are actually blessed globs, and (looking at the .xs source) Storable dies (because of its problematic underlying type) before I get the opportunity to use my own "smart" serialising code on the blessed glob.

Beginning to think my only option is to break IO::Handles down to tuples containing something like

.. and recreate using $class->new_from_fd($fd, $mode), but here I'm stumped as to how to work out what the opening mode of the thing is just from its glob.

Any suggestions please?

Addition #1: I've added example code below.

Addition #2: I'm actually not stumped by the open mode thing, was just being lazy - but is this the best way to do things?


In reply to Passing globs between threads by conrad

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.