Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Thanks for the lead. For the sub{} share stuff, I am still not sure it's necessity. But consider the following code, If I give anything try to alter the cloned structure, it give the Thread 2 terminated abnormally: Invalid value for shared scalar error.
$| = 1; use Data::Dumper; use threads;; use threads::shared; my @r = ( map+{ map{ $_ => [ 1 .. 2 ] } 'a' .. 'b' }, 1..2 );; my @s : shared = map shared_clone( $_ ), @r; sub A { while ( 1 ) { print Dumper \@s; sleep 3; } } sub B { while ( 1 ) { my $cmd = <STDIN>; chomp $cmd; push @s, { $cmd => time } } } $th1 = threads -> new ( 'A' ) ; $th2 = threads -> new ( 'B' ) ; $th1->join(); $th2->join();
This kind of assessment ( shareable R/W stuct ) would be more prior for my needs.

And for my ultimate purpose, I wish to share a struct which carrying different on-the-fly created objects, and they can cross access each other. Of cause I can change the style to share an array to indicate a "queue" and then every objects go inside the queue to look for action. However, this leads me to think, is if there's any transparent way for a complex stuct become shareable


In reply to Re^2: How to share complex data structure in threads ? by exilepanda
in thread How to share complex data structure in threads ? by exilepanda

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (10)
    As of 2015-07-03 17:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (54 votes), past polls