Perl multithreading and foreach Perl multithreading and foreach multithreading multithreading

Perl multithreading and foreach


You need to join all your threads from the main thread after they have all been started. Don't detatch if you don't want the interpreter to exit while the threads are still running.

...my $thrssh = threads ->create(\&ssh, $hostname);my $thrdns = threads ->create(\&dns, $hostname);...$thrssh->join();$thrdns->join();...

Regarding your edit: no, it's not right. You need to keep a reference to each thread you create, otherwise you can't join them.

Do something like:

my @thrs;foreach $mynode ($nodeset->get_nodelist) {    #...    $thrssh = threads ->create(\&ssh, $port, $hostname);    push @thrs, $thrssh;    #...}$_->join() for @thrs;