in reply to Re^4: Is it possible to create a single Hash-of-Hash.. with multiple threads.. in thread Is it possible to create a single Hash-of-Hash.. with multiple threads..
- No.
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.
- Yes.
Two possibilities:
- You can build a normal (non-shared) subhash and when complete, use threads::shared::shared_clone() to make a shared copy of it and assign a reference to the copy to a key/value pair in the main shared hash:
...
my %subhash;
... # populate it
lock %mainSharedHash;
$mainSharedHash{ $key } = shared_clone( \%subhash );
...
- You can create a shared subhash and assign a ref to it without needing to copy:
...
my %subhash :shared:
... # populate it
lock %mainSharedHash;
$mainSharedHash{ $key } = \%subhash;
- I do not understand the question.
You'll get better answers if you describe your actual application. Ie. Real requirements garner working responses.
- Again, your question makes no sense.
In a subroutine (or anywhere else), you can use unshared variables and/or shared variables as required.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|