Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: bug in threads::shared or is it just me?

by dada (Chaplain)
on Apr 10, 2012 at 15:36 UTC ( #964347=note: print w/replies, xml ) Need Help??


in reply to Re: bug in threads::shared or is it just me?
in thread bug in threads::shared or is it just me?

uhm, I don't agree on the necessary behaviour part, and I think you are mixing things up.

first of all, I'm returning the value of a variable, and this should work with any Perl variable, and it has nothing to do with scope. example:

sub foo { my $scoped_var = 42; return $scoped_var; } say foo();

of course the value "42" does not go out of scope. it would be very unkind if it did :-)

second, the sub that defines the variable is running in the same thread as main::. the anonymous sub I pass to threads->create() does run in another thread, and that's exactly why the variable is shared. but I'm not switching threads between the declaration and the usage outside of the sub.

I know that our works, as defining the variable outside of the sub does, but why? there is no mention in the threads::shared documentation about the fact that shared variables must be declared globally. furthermore, if you do the same thing with a scalar variable (eg. define it shared in a sub and returns it to the caller) everything works.

also, if you read my first post carefully, you will see that the keys of the hash (which are created in another thread as well) are effectively returned. just the values not. so it seems to me that there is (or better said there was, according to dave_the_m's reply below) some bug with container variables, threads::shared and scoping.

cheers,
Aldo

King of Laziness, Wizard of Impatience, Lord of Hubris

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-01-16 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?