Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Is it possible to create a single Hash-of-Hash.. with multiple threads..

by BrowserUk (Pope)
on May 03, 2014 at 07:46 UTC ( #1084870=note: print w/ replies, xml ) Need Help??


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..

  1. 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.

  2. Yes.

    Two possibilities:

    1. 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 ); ...
    2. 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;
  3. I do not understand the question.

    You'll get better answers if you describe your actual application. Ie. Real requirements garner working responses.

  4. 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.


Comment on Re^5: Is it possible to create a single Hash-of-Hash.. with multiple threads..
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1084870]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2015-07-30 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls