menth0l has asked for the wisdom of the Perl Monks concerning the following question:
In following example i'm testing several cases where shared object is assigned to shared hash. I observerd that if i use refcount on object reference or weaken on reference inside the shared hash after assignment this object fails to destroy.
I'm using:
ActiveState Perl 5.12.4
threads 1.86
threads::shared 1.40
Devel::Refcount 0.09
Scalar::Util 1.23
Is this a bug? And is it possible to keep weak references to shared objects inside a hash?
My output is:package Foo; use threads; use threads::shared; sub new { my ($class, $share) = @_; print "Init\n"; return $share ? bless shared_clone {} : bless {}; } DESTROY { print "Destroy\n"; } package main; use common::sense; use threads; use threads::shared; use Scalar::Util qw/weaken/; use Devel::Refcount qw(refcount); say "Test 1 (using two refcounts)"; { my %BAR :shared; my $foo = Foo->new(1); say refcount($foo); $BAR{foo} = $foo; say refcount($foo); } say "Test 2 (single refcount)"; { my %BAR :shared; my $foo = Foo->new(1); say refcount($foo); $BAR{foo} = $foo; #say refcount($foo); } say "Test 3 (no weaken)"; { my %BAR :shared; my $foo = Foo->new(1); $BAR{foo} = $foo; # weaken($BAR{foo}); } say "Test 4 (with weaken)"; { my %BAR :shared; my $foo = Foo->new(1); $BAR{foo} = $foo; weaken($BAR{foo}); }
My main concern is that i can't use weaken on my shared objects inside a hash.Test 1 (using two refcounts) Init 1 1 Test 2 (single refcount) Init 1 Destroy Test 3 (no weaken) Init Destroy Test 4 (with weaken) Init
I'm using:
ActiveState Perl 5.12.4
threads 1.86
threads::shared 1.40
Devel::Refcount 0.09
Scalar::Util 1.23
Is this a bug? And is it possible to keep weak references to shared objects inside a hash?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Shared objects and refcount/weaken bug?
by BrowserUk (Patriarch) on Mar 01, 2012 at 10:01 UTC | |
by menth0l (Monk) on Mar 01, 2012 at 10:13 UTC | |
by BrowserUk (Patriarch) on Mar 01, 2012 at 10:42 UTC | |
by menth0l (Monk) on Mar 01, 2012 at 11:01 UTC | |
Re: Shared objects and refcount/weaken bug?
by sundialsvc4 (Abbot) on Mar 01, 2012 at 14:31 UTC | |
by BrowserUk (Patriarch) on Mar 01, 2012 at 15:20 UTC | |
by BrowserUk (Patriarch) on Mar 01, 2012 at 22:21 UTC |
Back to
Seekers of Perl Wisdom