Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
threads::shared seems only serve for simple array, scalar or hash.

Look again at threads::shared::shared_close(). Eg:

use threads;; use threads::shared; my @r = ( map+{ map{ $_ => [ 1 .. 10 ] } 'a' .. 'z' }, 1..10 );; pp \@r;; [ { a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], b => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], c => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], d => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], e => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], f => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], g => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], h => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], i => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], j => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], l => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "m" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], n => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], o => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], p => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "q" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], r => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "s" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], t => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], u => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], v => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], w => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "x" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "y" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], z => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], }, { a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ... }, ] my @s : shared = map shared_clone( $_ ), @r; pp \@s; [ # tied threads::shared::tie { # tied threads::shared::tie a => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], b => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], c => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], d => [ # tied threads::shared::tie ... ], ... }, { # tied threads::shared::tie a => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], b => ... } ... ]

It won't clone subroutines, because that's not possible or logical.

However, whilst this allows you to share complex data structures, you'll generally find that it doesn't achieve what you think you want to achieve, and you'll probably come back asking why not.

If you would describe your application, there is usually a better way of achieving it.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

In reply to Re: How to share complex data structure in threads ? by BrowserUk
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
  • Outside of code tags, you may need to use entities for some characters:
            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 imbibing at the Monastery: (17)
    As of 2014-10-23 16:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (126 votes), past polls