29/11/2004 03:02:08, Michael G Schwern <[EMAIL PROTECTED]> wrote:
>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.
>
>
Ah but...that same POD also says:
Note that if this module is imported when threads has not yet been
loaded, then these functions all become no-ops. This makes it possible
to
write modules that will work in both threaded and non-threaded
environments.
In the absence of c<use threads>, threads::shared::share( ... ) becomes a noop,
so what ever you put in comes out unchanged.
>
>Nothing in there about throwing away the value of VARIABLE.
Indeed. The only positive conclusion from perlbug #30702 was that someone (I
can't find the reference just now), said that it shoudl at the very least be
documented. I thought that this would happen as a result of the perlbug being
closed.
> 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.
>
I could not agree more with this. It not only should happen, I would contend
that it *must* before sharing anything beyond simple scalars or more-than-one-
level-deep structures would become even remotely usable.
In addition, lock()ing individual elements of shared structures ought to be
possible too. The pod actually suggests that this is possible, but I've never
succeeded in getting it to work.
perl -Mthreads -Mthreads::shared
-wle"my %h:shared = (a=>1,b=>2);{ lock $h{a}; }"
lock can only be used on shared values at -e line 1.
>
>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!
>
Again, I agree completely.
>
>--
>Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern/
>Powered, not by a heart, but a sort of Wankel-Rotory Engine of Malevolence.
Twice the malevolence per unit of swept volume relative to a reciprocating
equivalent huh?
> http://www.goats.com/archive/031204.html
>
>
njs.