According to threads::shared on CPAN and perlthrtut, I should be able to declare a shared var using one of the following syntaxes:
use strict; use threads; use threads::shared; # pkg cfg { package cfg; %cfg::thash : shared = (); }
or this:
use strict; use threads; use threads::shared; # pkg cfg { package cfg; %cfg::thash = (); share(%cfg::thash); }
but the 1st gives a compile err and the 2nd gives a
runtime err.
By sheer luck/desperation, I tried:
which at least doesn't cause Perl to complain, but looks like a kludge to me... Is there a less wordy/neater way?use strict; use threads; use threads::shared; # pkg cfg { package cfg; %cfg::thash = (); threads::shared::share(%cfg::thash); }
2. Assignment
Assuming a valid declaration above, I need to assign values to the shared var, which happens to be a record structure ie I need to do this:
which gives the error: 'Invalid value for shared scalar '. I haven't been able to figure out a way around this yet. Really need an answer for this, as it's for a production system I'm writing.lock(%cfg::thash); $v1="A"; $v2="1"; $cfg::thash{$v1}{$v2} ="b";
In reply to Declaring/Assigning thread shared vars by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |