If you don't already have them, upgrade your threads and threads::shared modules to teh latest cpan versions. recent version have the ability to share objects:

#! perl -slw use strict; use threads; use threads::shared; use Junk; print $threads::VERSION; print $threads::shared::VERSION; sub thread { my $obj = shift; my $tid = threads->self->tid; sleep $tid; $obj->add( $tid, time() ); $obj->dump; return; } my $obj = Junk->new( abc => 123, pqr => 456 ); my $shrObj :shared = shared_clone( $obj ); my @threads = map threads->create( \&thread, $shrObj ), 1 .. 10; sleep 11; $shrObj->dump; $_->join for @threads; __END__ c:\test>junk5 1.71 1.26 bless({ # tied threads::shared::tie 1 => 1224113391, abc => 123, pqr => 456, }, "Junk") bless({ # tied threads::shared::tie 1 => 1224113391, 2 => 1224113392, abc => 123, pqr => 456, }, "Junk") ...

Junk.pm

package Junk; use Data::Dump qw[ pp ]; sub new { my $class = shift; return bless { @_ }, $class; } sub dump { my $self = shift; pp $self; } sub add{ my( $self, $key, $value ) = @_; $self->{ $key } = $value; return; } 1;

I haven't done much with this ability, and I don't know how effective it is at sharing more complex objects, but it is worth a try. From a quick scan of teh POD and inside the module I don't get how it works so I can't even make a prediction.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: shared complex scalars between threads by BrowserUk
in thread shared complex scalars between 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.