You can replace:
if( exists $copyRef->{ $step } ) { $copyRef = $copyRef->{ $step }; } else { lock %{ $copyRef }; $copyRef = $copyRef->{ $step } = &share( {} ); }
With:
lock %{ $copyRef }; $copyRef = $copyRef->{ $step } //= &share( {} )
Which is more compact, but not easier nor more efficient.
Two possibilities:
... my %subhash; ... # populate it lock %mainSharedHash; $mainSharedHash{ $key } = shared_clone( \%subhash ); ...
... my %subhash :shared: ... # populate it lock %mainSharedHash; $mainSharedHash{ $key } = \%subhash;
You'll get better answers if you describe your actual application. Ie. Real requirements garner working responses.
In a subroutine (or anywhere else), you can use unshared variables and/or shared variables as required.
In reply to Re^5: Is it possible to create a single Hash-of-Hash.. with multiple threads..
by BrowserUk
in thread Is it possible to create a single Hash-of-Hash.. with multiple threads..
by gsat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |