Reputation: 3692
I have threads that execute a sub which return an integer.
sub process_tasks {
...
return($nb_item_processed);
}
Here is how I launch the threads
map { threads->new(\&process_tasks, $_) } 1 .. $nb_threads;
How can I compute the sum of all value returned ?
Upvotes: 3
Views: 261
Reputation: 385546
The value returned by a thread is returned by join
.
use List::Util qw( sum );
my $sum =
sum
map { $_->join() }
map { async { process_tasks($_) } }
1 .. $nb_threads;
Upvotes: 5