Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by ikegami (Patriarch)
on Oct 20, 2006 at 17:17 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found