in reply to Sharing Package variables across threads
threads::shared has no effect on variables, package or otherwise.
The question is really whether you can make a shared package variable. share doesn't say it only works on lexical variables.
Let's try it to confirm:
$ perl -Mthreads -Mthreads::shared -E' share($x); $x = 4; async { say $x; ++$x; }->join; say $x; ' 4 5
So yes, you can.
Sharing adds magic to a variable, and thread cloning handles variables with this magic specially. It doesn't care whether the variable is accessible via the symbol table (package variable), via a function's pad (lexical variable), both or neither.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Sharing Package variables across threads
by metaperl (Curate) on Sep 01, 2011 at 08:15 UTC | |
by Anonymous Monk on Sep 01, 2011 at 09:50 UTC | |
by ikegami (Patriarch) on Sep 01, 2011 at 18:22 UTC | |
by ikegami (Patriarch) on Sep 01, 2011 at 18:24 UTC |