Dean Arnold wrote: > I've been pouring over the p5p archives trying to find > what the subject p5p summary item is about, but wo/ any luck. > Can someone point out the relevent thread title, or maybe > summarize what "threads::shared could share aggregates > properly with only Perl level changes to shared.pm" > means ?
It means that something like this would DWIM: my $x : shared; $x = [ { 'complex' => 'aggregate' }, [ qw/ currently not sharable / ] ]; To do that now you'd have to do: my $x : shared; $x = &share([]); push(@$x, &share({}), &share([])); $$x[0]{'complex'} = 'aggregate'; push(@{$$x[1]}, qw/ currently not sharable /); The problem comes with copying complex structures: my $x = [ { 'complex' => 'aggregate' }, [ qw/ currently not sharable / ] ]; my $y : shared; $y = $x; How do you handle the assignment? With regular scalars, $x and $y share copies of the same structure such that changes via $x are visible via $y. However, with the above, you'd have to clone the structure pointed to by $x and assign that clone to $y such that they would be independent. And it gets worse: Suppose the hash inside $x is already shared. Technically, you don't need to clone that portion. And then you'd have to distinguish (in code) how to differentiant between the above, and say $z = $x when both are already shared (in which case no cloning is needed). The rules would need to be defined in detail and then documented clearly so that programming don't get befuddled trying to figure them out. Thread::Queue has the Perl code needed for making 'complete' shared clones of data structures (i.e., all parts whether shared or not are cloned). Tweaking it to not clone already shared portions is trivial. Then we just need a tie-in with the assignment operator. Or perhaps we could just provide a function: $y = shared_clone($x);