I am studying Perl multithreading. My code is:
use warnings;
use threads;
use threads::shared;
$howmany = 10;
$threads = 5;
$to = int($howmany / $threads);
for (0 .. $threads) {$trl[$_] = threads->create(\&main, $_);}
for (@trl) {$_->join;}
sub main {
for (1 .. $to) {
print "test\n";
}
}
exit(0);
I want to print the word test $howmanyonce in streams $threads. This code prints the test 12 times. Where is the problem?
source
share