Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^3: Shared hash within shared hash of hash???

by dave_the_m (Prior)
on Jan 02, 2013 at 17:30 UTC ( #1011320=note: print w/replies, xml ) Need Help??

in reply to Re^2: Shared hash within shared hash of hash???
in thread Shared hash within shared hash of hash???

Do i need to use lock $hash{foo} ; or lock ( \%hash ) ; if foo is used as shared_clone ?
You only need locking to ensure the consistency of your own data when shared between threads. Perl already does its own internal locking on shared structures to ensure internal consistency. So for example
my %h : shared; $h{foo} = share ({}); ... $h{foo}{bar} = 1; # in thread 1 $h{foo}{bar} = 2; # in thread 2
Here, there is no locking, so $h{foo}{bar} may end up as 1 or 2; but it won't end up as something else; nor will the {foo} or the {bar} slots of the respective hashes get corrupted.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011320]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-06-19 02:58 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.