Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Threads: why locking is required when using shared variables

by ikegami (Pope)
on Oct 20, 2006 at 17:17 UTC ( #579645=note: print w/ replies, xml ) Need Help??


in reply to Re: Threads: why locking is required when using shared variables
in thread Threads: why locking is required when using shared variables

That reminds me of a very useful bit of information reguarding locking. A single lock variable can be used to control access to multiple shared variables. For example,

my $list_head : shared; # Access controlled by $list_head. my $list_tail : shared; # Access controlled by $list_head. sub ... { ... { lock($list_head); ... code that uses $list_head and/or $list_tail ... } ... }

It doesn't matter which variable is used as to control access to a give shared variable, as long as you *always* use the same lock variable to control access to that shared variable.


Comment on Re^2: Threads: why locking is required when using shared variables
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-10-01 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (38 votes), past polls