jak uzyskać dostęp do obiektów perla w wątkach

Mam nadzieję, że ktoś z was może mi pomóc w rozwiązaniu mojego problemu. Próbowałem uzyskać dostęp do globalnej wspólnej tablicy obiektów podczas obliczeń wątkowych i zawsze otrzymuję błąd „użycie niezainicjowanej wartości”, chociaż mogę wydrukować ich skróty.

Ponadto nie mogę zmienić moich obiektów, dzięki pracy z obiektami seqio z bioperl.

Poniższy przykład pokazuje mój problem.

Z góry dziękuję.

klasa obiektu:

package obj;

use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);

sub new(){
    my $class=shift;
    my $this = {};
    $this->{"data"} = ();   
    bless($this,$class);
    return($this);
}

sub getData(){
    my $this=shift;
    return $this->{"data"};
}

sub setData($){
    my $this=shift; 
    $this->{"data"}=shift;
}

Klasa testowa:

use strict;
use warnings;
use threads;
use threads::shared;
use obj;

my @objs : shared;
foreach (0..2){
    my $o = obj->new();
    $o->setData($_);
    push @objs, share($o);  
}

my @threads=();
$#threads=3;

my $started;
for (my $i=0; $i<10; $i+=$started){
    $started=0;
    foreach (0..$#threads){
        if (not defined $threads[$_]){
            $threads[$_]=threads->new(\&run,(\@objs));
            $started++; 
        } elsif($threads[$_]->is_joinable()){
            $threads[$_]->join();
            $threads[$_]=threads->new(\&run,(\@objs));
            $started++;
        }           
    }   
}
my $running=1;
while ($running>0) {
    foreach (@threads) {    
        if (defined $_){
            $_->join if ($_->is_joinable());    
        }               
    }
    $running = scalar(threads->list(threads::running));       
}   

sub run($){
    my $objs=shift;

    print $_." " foreach (@{$objs});
#   print $_->getData()." " foreach (@{$objs}); try to access data

    print "\n";     
}

questionAnswers(1)

yourAnswerToTheQuestion