FYI, here's some code. Uncomment/comment Clone/Storable, clone/dclone as reqd:

#!/usr/bin/perl -w + use strict; use threads; use threads::shared; use Clone qw(clone); #use Storable qw(dclone); + my ( $thr1, # thread handle $key, $v1, $v2, $v3, $tmp1, $tmp2, $key1, $key2, $key3 ); + # pkg test { + package cfg; + %cfg::thash = (); threads::shared::share(%cfg::thash); } + { lock(%cfg::thash); $tmp1 = {}; $tmp2 = {}; share($tmp1); share($tmp2); + + $v1="B"; $v2="2"; $cfg::thash{$v1} = $tmp1; $cfg::thash{$v1}{$v2} = $tmp2; $cfg::thash{$v1}{$v2}{server} ='b.a.com'; print "$cfg::thash{$v1}{$v2}{server}\n"; + $tmp1 = {}; share($tmp1); $tmp2 = {}; share($tmp2); + $v1='A'; $v2='1'; $cfg::thash{$v1} = $tmp1; $cfg::thash{$v1}{$v2} = $tmp2; $cfg::thash{$v1}{$v2}{server} ='a.a.com'; print "$cfg::thash{$v1}{$v2}{server}\n"; print "$cfg::thash{'B'}{'2'}{server}\n"; + $tmp1 = {}; share($tmp1); $tmp2 = {}; share($tmp2); $v1='C'; $v2='3'; $cfg::thash{$v1} = $tmp1; $cfg::thash{$v1}{$v2} = $tmp2; $cfg::thash{$v1}{$v2}{server} ='c.a.com'; + } for $key1 (sort keys %cfg::thash) { print "ISP:$key1\t"; for $key2 (sort keys %{$cfg::thash{$key1}} ) { print "RANK:$key2\t"; for $key3 (sort keys %{$cfg::thash{$key1}{$key2}}) { print "$key3 $cfg::thash{$key1}{$key2}{$key3}\n"; } } } + + $thr1 = threads->new(\&sub5, "one"); exit; + sub sub5 { my $thr = $_[0]; my %thash=(); my $key ='test'; while (1) { { lock(%cfg::thash); print "Before: thread $thr: thash = $cfg::thash{'A'}{'1'}{ser +ver}\n"; print "After: thread $thr: thash = $cfg::thash{'B'}{'2'}{serv +er}\n"; # $thash{$key} = dclone($cfg::thash{'B'}); $thash{$key} = clone($cfg::thash{'B'}); } } }

In reply to Re^2: Using clone/dclone with threads by Anonymous Monk
in thread Using clone/dclone with 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.