Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

lock with references

by ISAI student (Scribe)
on Dec 20, 2012 at 11:28 UTC ( [id://1009722]=perlquestion: print w/replies, xml ) Need Help??

ISAI student has asked for the wisdom of the Perl Monks concerning the following question:

Hello all. Are there any known limitations for using a derefernced reference to a shared variable?

I.E. is this code:
my $var1 : shared; sub vary { $var_ref = shift ; lock ($$var_ref); $$vary_ref = 1 ; } vary (\$var1);
equivalent to this code?
my $var1 : shared; $var_ref = shift ; { lock ($$var_ref); $$vary_ref = 1 ; }
Thanks.

Replies are listed 'Best First'.
Re: lock with references
by BrowserUk (Patriarch) on Dec 20, 2012 at 14:18 UTC

    I can honestly say that I don't remember encountering any particular limitations with using references to shared variables, nor can I intuit anything obvious why they shouldn't be just fine.

    However, I also cannot remember any good reason for using references to shared variables.

    And a quick search of my source files didn't turn up any obvious examples, but then it is a little hard to search for.

    So both my instincts and experience are telling me that whilst I cannot see any particular reason for doing it, it should be just fine....

    ...but then comes this feeling that if you hadn't encountered some anomaly, you wouldn't be asking...

    so, maybe I'll just keep quiet rather than get seen to be caught out by a sucker punch.


    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.
      Relax, I have yet to encounter one, and not into punching anyone. I am doing major rework on a huge script, and trying to make the code more modular, w/o changing the basic algorithm. Hence, passing hundreds of lines of code to some subroutines, which setup shared variables. I have to use references, as two or more shared hashes are changed in 1 chunk of code, and seperating the commands is far too time consuming. I have never worked with threads, and was afraid of some unknown (to me) "gotcha". perlmonks is, IMHO, one of the best place to ask about this, with regards to PERL, of course.
        I have to use references, as two or more shared hashes are changed in 1 chunk of code, and seperating the commands is far too time consuming....I have never worked with threads,...

        I've done lots of work with threads; and that first sentence makes no sense to me at all.

        Are these references, references to shared scalars as indicated in your first post?

        Or references to hashes as implied here?

        Or possibly references to scalars that are values in a shared hash?

        Or references to shared scalars that are values in a non-shard hash?

        Or...?


        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.

        RIP Neil Armstrong

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-19 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found