http://www.perlmonks.org?node_id=374821


in reply to share() bug? ( [perl #30702] )

It's not a bug. It's a side effect of using tie() for shared arrays and hashes.

Observe:

use threads; use threads::shared qw(share); my @foo :shared = (1,2,3); # same as: share( @foo ); @foo = (1,2,3) my @bar = (1,2,3); share( @bar ); print "foo = @foo, tied foo = ".(tied @foo)."\n"; print "bar = @bar, tied bar = ".(tied @bar)."\n"; __END__ foo = 1 2 3, tied foo = threads::shared::tie=SCALAR(0x82b714) bar = , tied bar = threads::shared::tie=SCALAR(0x80a270)

Shared arrays, as shared hashes, are implemented using tie(), as can be observed from the output of the tied() function.

And losing / hiding the original value of something, is a known side-effect of tie(), as far as I know.

So there's no easy solution, I'm afraid. Fixing tie() to keep the original value, may be in order, but may also break a lot of programs.

Fixing threads.pm and threads::shared to not use tie() would be best, but not something we're going to see in the 5.8 life cycle of Perl.

I think that's basically the dilemma.

Liz