menth0l has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| 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 locked_user 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 |