When I tried some threaded code I found that the &share() function was next to useless for hashes and arrays. The documentation (threads::shared) appears to pretty much agree:
BUGS AND LIMITATIONS
When share is used on arrays, hashes, array refs or hash refs, any data they contain will be lost.
I found that the trick was to declare shared arrays/hashes. Then you can put references to those shared items into other shared data structures.
So, where you have:
I would try:sub thread_worker { my $n = shift; # thread N my @args = shift; my %temp = (); .... while(1) { .... $totals{$n}->{STEPS} = $s; # record step $temp{$s}=$random; # add value to per +-thread hash $totals{$n}->{HASH}= &share( \%temp ); # copy results to +shared structure .... } }
and see if it works any better. (It did for me.)sub thread_worker { my $n = shift; # thread N my @args = shift; my %temp : shared = (); # Make shared $totals{$n}->{STEPS} = 0 ; # Nothing yet $totals{$n}->{HASH} = \%temp ; # Set ref to shared result +s .... while(1) { .... $totals{$n}->{STEPS} = $s; # record step $temp{$s}=$random; # add value to per-thread +hash # REMOVED: $totals{$n}->{HASH}= &share( \%temp ); .... } }
In reply to Re: threads :: shared hash of hashes (array of arrays)
by gone2015
in thread threads :: shared hash of hashes (array of arrays)
by konstant1n
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |