Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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.

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


Comment on Re: share() bug? ( [perl #30702] )
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-07-10 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (216 votes), past polls