On Fri, 29 Feb 2008 Dave Mitchell wrote
On Wed, Feb 27, 2008 at 08:15:36AM -0800, Dean Arnold wrote:As to shared object destruction:pre-5.10.0: once per thread, requires some extra bookkeeping to make sure it "does the right thing" 5.10.0: once in the last referencing thread (fixed in CORE)
Huh?
use warnings;
use strict;
use threads;
use threads::shared;
sub DESTROY { warn "DESTROY $_[0]\n" }
my $h = bless {};
share $h;
threads->new(sub {})->join;
$ perl5100t /tmp/p
DESTROY main=HASH(0x98fb844)
DESTROY main=HASH(0x98748c4)
$
I had a feeling that there was some significance attached to the order of the blessing and sharing. Now I'm not so sure...
...but I have tried the following:
---Test-1---
I add a little to the above, ending up with:
use warnings;
use strict;
use threads;
use threads::shared;
print "threads v$threads::VERSION",
" & threads::shared v$threads::shared::VERSION\n" ;
sub DESTROY { my $s = shift ; warn "DESTROY $s: ", %$s, "\n" }
my $h = bless {Test => -1} ; # )
warn "Object \$h is $h: ", %$h, "\n" ; # ) Object construction
share $h; # )
threads->new(sub {})->join;
which gives me:
Perl v5.10.0 & threads v1.67 & threads::shared v1.14
Object $h is main=HASH(0x22b08c): Test-1
DESTROY main=HASH(0x18b305c):
DESTROY main=HASH(0x22b08c):
and:
Perl v5.8.8 & threads v1.69 & threads::shared v1.17
Object $h is main=HASH(0x6054e0): Test-1
DESTROY main=HASH(0x722ca0):
DESTROY main=HASH(0x6054e0):
Noting the empty Hashes !
So, whatever share $h does, it doesn't appear to be to cause the thing
pointed to by $h to become shared -- or perhaps it does, but empties it.
---Test-2---
Replacing the object construction bit by:
my %b : shared = (Test => -1) ;
my $h = bless \%b ;
gives:
Perl v5.10.0 & threads v1.67 & threads::shared v1.14
Address \%b is: HASH(0x1887814), Value: Test-2
DESTROY main=HASH(0x1887814): Test-2
and:
Perl v5.8.8 & threads v1.69 & threads::shared v1.17
Address \%b is: HASH(0x6b0f80), Value: Test-2
DESTROY main=HASH(0x6b0f80): Test-2
Which is the expected behaviour for V5.10.0, but not for v5.8.8 ?
Note that the shared hash is blessed: suggesting the order is
significant.
---Test-3---
However:
my $h = &share({Test => -3}) ;
warn "Scalar \$h is $h:", %$h, "\n" ;
bless $h ;
which you might think would work, doesn't:
Perl v5.10.0 & threads v1.67 & threads::shared v1.14
Scalar $h is HASH(0x22b08c):
DESTROY main=HASH(0x18b52d4):
DESTROY main=HASH(0x22b08c):
and similarly for v5.8.8.
---Test-4---
So... perhaps it's share that I don't understand, so I tried.
my $h = &share({}) ;
%$h = (Test => -4) ;
bless $h ;
warn "Object \$h is $h: ", %$h, "\n" ;
gives:
Perl v5.10.0 & threads v1.67 & threads::shared v1.14
Object $h is main=HASH(0x22b08c): Test-4
DESTROY main=HASH(0x18b72e4): Test-4
DESTROY main=HASH(0x22b08c): Test-4
and similarly for v5.8.8.
---Conclusion---
Well, I'm stumped.
Whatever share $h does, it doesn't appear useful when $h is a ref to
something.
Whatever my $h = &share({}) does, it's not the same as
my %b : shared ; my $h = \%b ;
Whatever &share({a => 1}) does, it doesn't return a ref to an anonymous
hash containing a => 1 !!
I don't see any difference between v5.10.0 and 5.8.8... could be that I'm using late model threads & threads::shared with v5.8.8 ?
Chris -- Chris Hall highwayman.com +44 7970 277 383
signature.asc
Description: PGP signature
