in reply to Re: Re: Threading: Invalid value for shared scalar
in thread Threading: Invalid value for shared scalar
Changing the implicit hash creation to explicit hash creation will fix the problem. the perl thread model is predicated on non-shared data by default. This forces us to deliberately share all the structures. (It is a pain).#non shared hash version my %abc; my @parents = qw( a b c ); my @children = qw( 1 2 3 4 ); for my $parent ( @parents ) { for my $child ( @children ) { $abc{ $parent }{ $child } = 1; } }
The lexical scopes for %p and %c will go away, but the references will remain in the hash, preventing garbage collection.# shared hash version. my %abc : shared ; my @parents = qw( a b c ); my @children = qw( 1 2 3 4 ); for my $parent ( @parents ) { unless (exists $abc{$parent}) { my %p : shared; $abc{ $parent } = \%p; } for my $child ( @children ) { unless ( exists $abc{$parent}{$child} ) { my %c : shared; $abc{$parent}{$child}=\%c; } $abc{ $parent }{ $child } = 1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Threading: Invalid value for shared scalar
by hexcoder (Curate) on Jul 03, 2015 at 12:05 UTC | |
by BrowserUk (Patriarch) on Jul 03, 2015 at 12:42 UTC | |
|
Re^4: Threading: Invalid value for shared scalar
by Anonymous Monk on Feb 26, 2015 at 13:10 UTC |