in reply to Threads inside Objects & Sharing
Hi,
This works for me. I moved the "test" routine to the top level and receives $self and $x1. Likewise, create provides $self and $x1 for the arguments.
sub test { my ($self, $x1) = @_; ... }; sub startThread { my $self = shift; my $thr; share ($self->{x2}); print "threads->create \$self{x1}=$self->{x1}\n"; $thr = threads->create('test', $self, $self->{x1}); $thr->detach(); }
Output
... A: closing thread $self{x2}=558 A=558 B=766 C=970 B: closing thread $self{x2}=766 A=558 B=766 C=970 C: closing thread $self{x2}=970 A=558 B=766 C=970 A=558 B=766 C=970 A=558 B=766 C=970 A=558 B=766 C=970
Regards, Mario
In Section
Seekers of Perl Wisdom