When I use exit or die, it kills the entire program.
foreach my $t (threads->list())
{
$t->exit;
$count++;
}
Usage: threads->exit(status) at main.pl line 265
Perl exited with active threads:
9 running and unjoined
0 finished and unjoined
0 running and detached
Any ideas?
To ignore a thread that is being executed, return back control and throw away whatever it may output, the right method to use is
detach, notexit.See
perldoc perlthrtut– Ignoring a Thread.perldoc threadsexplains why the code exits:There may be a way to achieve instant termination (didn’t work for me on Windows):
The documentation also suggests another way, using the
set_thread_exit_onlymethod (Again, didn’t work for me on Windows):The example below makes use of a kill signal to terminate the
$unwantedthread: