0
這是我的代碼。錯誤代碼爲'線程1異常終止:共享標量的值無效'
該代碼有一些關於散列共享的問題。
use strict;
use warnings;
use threads;
use threads::shared;
my %db;
share(%db);
my @threads;
sub test{
my $db_ref = $_[0];
my @arr = ('a','b');
push @{$db_ref->{'key'}}, \@arr;
}
foreach(1..2){
my $t = threads->new(
sub {
test(\%db);
}
);
push(@threads,$t);
}
foreach (@threads) {
$_->join;
}
錯誤代碼。
Thread 1 terminated abnormally: Invalid value for shared scalar at test1.pl line 13.
Thread 2 terminated abnormally: Invalid value for shared scalar at test1.pl line 13.
我waana使用線程::共享。
但我不知道什麼是問題。
help me plz〜