On Mon, Nov 29, 2004 at 02:41:24AM -0000, Nigel Sandever wrote:
> I don't think that you are doing anything wrong. I have *never* seen share() 
> return a reference to a hash or an array that had contents. That is to say, 
> whenever you pass a reference to a hash or any array that hash something in 
> it, 
> to share(), it *always* empties it. 
> 
> perl -Mthreads -Mthreads::shared -wle"print %{ &share( {a=>1,b=>2}) },'?';"
> ?
> 
> Try any variation you like on that, it will always return a reference to an 
> empty hash or array. Scalars retain any pre-sharing value they might have.
> 
> This is 'by design'.

Riddle me this.

$ perl -Mthreads::shared -wle 'print %{ &share( {a=>1,b=>2}) };'
b2a1

With threads off share() returns you the reference.  So one behavior or
the other is wrong.  In fact I remember specifically fixing threads::shared
in disabled mode to do this.  There's even a test for it!
http://www.nntp.perl.org/group/perl.perl5.porters/65753

Additionally the docs for threads::shared say this:

       share VARIABLE
           "share" takes a value and marks it as shared. You can share a
           scalar, array, hash, scalar ref, array ref or hash ref.  "share"
           will return the shared rvalue but always as a reference.

Nothing in there about throwing away the value of VARIABLE.  "Will
return the shared rvalue" is pretty clear to me.

Regardless of threading voodoo, share() can do the work around I've done.
Copy the contents!  This is certainly more correct than silently throwing
them away.

If I'm completely wrong and share() was never designed to hang onto the
contents the docs should be clarified AND MOST IMPORTANTLY it should yell
at you when you feed it a non empty reference!


-- 
Michael G Schwern        [EMAIL PROTECTED]  http://www.pobox.com/~schwern/
Powered, not by a heart, but a sort of Wankel-Rotory Engine of Malevolence.
        http://www.goats.com/archive/031204.html

Reply via email to