Jerry D. Hedden wrote:
I've attached my reworked version of T::Q that I think takes
care of circular references. Would you mind giving it a
going over? (It passes all the currents tests in its test
suite, so I know I didn't break anything.) Thanks.
My sample worked OK *after* I removed the Data::Dumper
print; apparently, it has some issues w/ circular
references as well (I tried setting Deepcopy and
Purity, to no avail); I suspect its due to the fact
that references to shared elements don't have the same
stringified value, so it doesn't actually look like
a circular ref.
Anyway, my updated version of the test follows.
- Dean
use strict;
use warnings;
use threads;
use threads::shared;
use Thread::Queue;
use Data::Dumper;
my $q = Thread::Queue->new();
my $x = [ { 'complex' => 'aggregate' },
[ qw/ currently not sharable / ] ];
my $thrd = threads->create(\&receiver, $q);
$q->enqueue($x);
$thrd->join();
print "*** non-recursive OK\n";
#
# Make it a recursive structure
# (!!! this will choke)
#
push @$x, $x;
$thrd = threads->create(\&receiver, $q);
$q->enqueue($x);
print "*** enq'd\n";
$thrd->join();
print "*** recursive OK\n";
sub receiver {
my $q = shift;
print "*** starting child\n";
my $data = $q->dequeue();
print "*** deq'd\n";
if ($#$data == 1) {
print "** in child:\n", Dumper($data), "\n";
}
elsif (($#$data != 2) || (ref $data->[2] ne 'ARRAY')) {
print "NOT OK: $#$data $data $data->[2]\n";
}
else {
print "** in child:\n", Dumper($data->[0], $data->[1]), "\n";
}
}