I have a multi-thread perl script using threads
, works ok but when it tries to kill the hanged threads I got an error and script exists:
for (0..$threads-1) {
$trl[$_] = threads->create(\&my_sub, $_);
$SIG{ALRM} = sub {
if ($trl->is_running) {
$trl->kill('ALRM');
}
}
}
for (@trl) {
alarm 10;
$_->join;
}
and
sub my_sub {
$SIG{ALRM} = sub {
threads->exit(1);
};
while (@site) {
{
lock(@site);
$url = shift @site;
}
and the error:
Can't call method "is_running" on an undefined value at test.pl line 61.
Perl exited with active threads:
9 running and unjoined
40 finished and unjoined
0 running and detached
the line 61 is:
if ($trl->is_running) {