Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: share() bug? ( [perl #30702] )

by liz (Monsignor)
on Jul 15, 2004 at 20:40 UTC ( #374821=note: print w/replies, xml ) Need Help??

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.


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 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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-10-20 06:05 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (112 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!