Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Declaring/Assigning thread shared vars
by BrowserUk (Patriarch) on Nov 18, 2004 at 00:56 UTC | |
by diotalevi (Canon) on Nov 18, 2004 at 01:47 UTC | |
by BrowserUk (Patriarch) on Nov 18, 2004 at 03:07 UTC | |
|
Re: Declaring/Assigning thread shared vars
by ikegami (Patriarch) on Nov 18, 2004 at 00:08 UTC | |
by Anonymous Monk on Nov 18, 2004 at 02:03 UTC | |
|
Re: Declaring/Assigning thread shared vars
by Anonymous Monk on Nov 18, 2004 at 01:47 UTC | |
|
Re: Declaring/Assigning thread shared vars
by Anonymous Monk on Nov 18, 2004 at 06:53 UTC | |
by BrowserUk (Patriarch) on Nov 18, 2004 at 09:01 UTC | |
by Anonymous Monk on Nov 18, 2004 at 23:34 UTC | |
by BrowserUk (Patriarch) on Nov 19, 2004 at 03:16 UTC |