スレッドからパッケージ変数にアクセスする際に問題があります。これは大きなプロジェクト用なので、コードの関連部分を抽出してみます。
オブジェクト指向部分にはスレッドモジュールとMooseを使用しています。
our $thread2;
around 'new' => sub {
[...]
threads->create( \&_thread1Func, $shared_self );
if (!$thread2) {
$thread2 = threads->create( \&_thread2Func, $shared_self );
$thread2->detach();
}
}
sub _thread1Func {
$thread2->kill('SIGUSR1');
}
sub _thread2Func {
$SIG{'USR1'} = sub { [...] };
while (1) {
sleep 5;
[...]
}
}
次のエラーが表示されます。
Thread N terminated abnormally: Can't call method "kill" on an undefined value at XXXX.pm line n.
線をn
指しながら$thread2->kill('SIGUSR1');
$thread2 を宣言our
すると、パッケージ全体から見えるようになると考えていました。
何が起こっているかについて何か考えはありますか?