Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by BrowserUk (Patriarch)
on May 03, 2014 at 07:46 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found