#!/usr/bin/perl -w
use strict;
use threads;
sub SubFunction;
print "main: ".threads->tid."\n";
threads->new(\&SubFunction, "localhost");
threads->new(\&SubFunction, "localhost");
threads->new(\&SubFunction, "localhost");
threads->new(\&SubFunction, "localhost");
threads->new(\&SubFunction, "localhost");
# loop through threads and wait for remaining
foreach my $thread (threads->list) {
#print "remaining threads: ".threads->list."\n";
if ($thread->tid && !threads::equal($thread, threads->self)) {
$thread->join; # join childs only
}
}
sub SubFunction {
print "- thread: ".threads->tid."\n";
#system("ping $_[0]");
my $fh;
open($fh, '-|', "ping.exe $_[0]") or die "couldn't open pipe!";
print while (<$fh>);
close($fh);
}