I am passing a hash-of-hashes from one thread to another.
I found that if I iterate over the inner hashes with each %{$outer{inner}}, it loops forever on the first key. It looks like every use of $outer{inner} is resetting the hash iterator for the inner hash.
This program illustrates the problem:
#!/usr/bin/perl use strict; use threads; use threads::shared; my %outer :shared; $outer{inner} = &share({}); %{$outer{inner}} = map { $_ => $_ } 'a'..'z'; ################################################################# print "By taking a reference first...\n"; my $iter = 0; { my $ref = $outer{inner}; while ($iter++ < 10) { last unless (my ($k, $v) = each %$ref); print "$k\n"; } } print "...and so on\n\n"; ################################################################# print "By de-ref the shared hash-of-hashes each time...\n"; $iter = 0; while ($iter++ < 10) { last unless (my ($k, $v) = each %{$outer{inner}}); print "$k\n"; } print "...and so on\n";
... which produces the following output:
By taking a reference first... w r a x d j y u k h ...and so on By de-ref the shared hash-of-hashes each time... w w w w w w w w w w ...and so on
When I comment out use threads, everything works normally. I tried reading through shared.xs, etc but I can't find an obvious bug.
Any ideas?
-- kevin
In reply to threads::shared resets %hash iterators by kbrint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |