in reply to Re^3: Locking hash values
in thread Locking hash values

To continue with this theme why not to share a ref to a hash. Like so:
... use threads; use threads::shared; ... my $href : shared; $href = &share({}); ... # Lock block { lock $href; $href->{mykey} = 'myval'; } ...
For more see perldoc threads::shared.

- BR

Replies are listed 'Best First'.
Re^5: Locking hash values
by ikegami (Patriarch) on Dec 18, 2006 at 19:45 UTC

    If the OP wanted to lock the hash, lock(%hash) would be sufficient. However, he wants to lock an element of the hash.

      yeah, I could lock the whole hash, but I'd much rather be able to lock hash-values to keep from blocking too much.