I’m using multiple threads in my Perl script and join them at the end by this code snipped:
my @running = threads->list(threads::running);
while ($#running > -1) {
foreach (@thrs) {
$_->join() if $_->is_joinable();
}
@running = threads->list(threads::running);
}
But in 50% I get the error message Perl exited with active threads.
Can someone help me? Thx
You stop looping when there are no more running threads, but you should only stop looping when there are no more threads of any kind. In other words, you don’t check if there are joinable threads. Solution:
Of course, that uses 100% CPU. The simple way to avoid that is to use: