in reply to Re^6: Avoid Locking Entire Hashes
in thread Avoid Locking Entire Hashes
. I hope you are able to see my point here.
Yes I can. My untested, typed into the browser, attempt to modify the original safe_set() function to demonstrate the idea that there is no advantage to using a mirrored data structure was broken. Sorry.
For real usage it would have to be something more like this:
sub safe_set { my( $ref, $k, $v ) = @_; die 'Bad first arg' unless ref( $ref ) eq 'HASH'; if( exists $ref->{ $k } and ref( $ref->{ $k } ) eq 'SCALAR' and is_shared( $ref->{ $k } ) ) { lock ${ $ref->{$k} }; ${ $ref->{$k} } = $v; } else { lock $ref; $ref->{ $k } = \my $vs :shared = $v; } }
Test, fix-up and sweeten to taste.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Avoid Locking Entire Hashes
by jagan_1234 (Sexton) on Jun 15, 2011 at 22:04 UTC | |
by BrowserUk (Patriarch) on Jun 15, 2011 at 22:25 UTC |