Well, I think you are trying to break thread safety and now you're getting bitten by undefined behavior.

> I know threads::shared can't share deep data structure,

according to the docs that's not true, you can share deep data structures as long as you also share any nested reference.

share(VARIABLE)

Shared variables can only store scalars, refs of shared variables, or refs of shared data (discussed in next section):

> and any fix for this approach?

You can always use shared_clone for read access.

And of course you can explicitly share singular scalars inside your nested data structure to allow writing.

shared_clone(REF)

shared_clone takes a reference, and returns a shared version of its argument, performing a deep copy on any non-shared elements. Any shared elements in the argument are used as is (i.e., they are not cloned).

If that's not good enough because you can't/don't want to predict the structure of your nested data, you might try Data::Dumper or Data::Dump for serializing it into a shared string. The receiving end can easily unpack it again.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re: use Devel::Pointer in threads by LanX
in thread use Devel::Pointer 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!
  • 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.