Wiggins has asked for the wisdom of the Perl Monks concerning the following question:
Now we have a hash in shared spece, and anonymous arrays in shared space, and references in the hash to the arrays.
Now a 2nd thread reads the hash every 60 seconds looking for data. Locking the entire hash during the access of a single entry blocks access for updating of all the other hash members. The solution is the locking of an individual member referenced by an entry in the hash.
These do not work:
(thread failed to start: lock can only be used on shared values at ./capturetest line 242.)
(shotgun approach code)
############################################## # Move data into ':shared' hash of arrays # setting all values for the entry, from # thread local - global values sub init_Contract { $Contracts{$key} = &share([]); # hook shared anonymous array # into shared hash { #lock $Contracts{$key}; #lock only this single entry #lock $$Contracts{$key}; #lock only this single entry #lock $Contracts{$$key}; #lock only this single entry #lock $Contracts{$key}[STATE]; $Contracts{$key}[STATE]=$state; #set value in anonymous array +. $Contracts{$key}[START]=$start; ...
?? How is a dynamically created, shared, anonymous, array locked.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Locking dynamicaly created, shared, array
by dave_the_m (Monsignor) on Nov 14, 2006 at 15:46 UTC | |
by Wiggins (Hermit) on Nov 14, 2006 at 16:28 UTC |