What kind of test are you doing via telnet? If you just want to check connectivity, a select loop on multiple sockets would suffice, no threads needed:

$\=$/; use IO::Socket::INET; my @hosts = qw(pantagruel gargantua foo bar quux); my (%active,%sockets); my $maxconn = 30; # or as much as your OS permits ;-) my $timeout = 20; sub setup_sock { my $fh = eval { IO::Socket::INET->new( PeerAddr => "$_[0]:23", Blocking => 0, ) }; unless ($fh) { print "$_[0] not reachable"; return; } $active{$_[0]} = $fh; $sockets{fileno($fh)} = $_[0]; # print "$_[0] fileno ",fileno($fh); } sub close_sock { my $fileno = shift; my $host = $sockets{$fileno}; $active{$host}->close; delete $active{$host}; delete $sockets{$fileno}; } sub set_bits { my $rin; for (keys %active) { vec($rin, fileno($active{$_}),1) = 1; } $rin; } while (@hosts || keys %active) { # $c++; print "pass $c"; setup_sock(shift @hosts) while ($maxconn > keys %active and @hosts +); my $rin = set_bits; my $rout; select($rout=$rin,undef,undef,$timeout); # if there has been a timeout, there has been no response, # and $rout has no bit set. mark those hosts as unreachable if ($rout eq "\0") { for(0..unpack"B*",$rin) { if (vec $rin,$_,1) { print "no answer from $sockets{$_} (fileno $_)"; close_sock($_); } } } for(0..unpack"B*",$rout) { if (vec $rout,$_,1) { print "$sockets{$_} ($_) is alive"; close_sock($_); } } }

If there's more to it, i.e chatting with the AP, then you might want to fire off threads for the check part (i.e. the close_sock() sub above.)

update: mhm. Maybe the bottleneck is moved to IO::Socket::INET->new() that way...

update2: nope ;-) ... you get to wait the full timeout only once per $maxconn if the %active hash is filled up with unresponsive peers.

In reply to Re: Testing many devices - are threads the answer? by shmem
in thread Testing many devices - are threads the answer? by McDarren

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":