thread
am 08.11.2007 04:15:12 von LarryHi peeps,
below is the code of a script that spawns a new thread whenever
it gets a new request:
#!/usr/bin/perl -w
use strict;
use warnings;
use IO::Socket::INET;
use Data::Dumper;
use threads;
use IO::Handle;
STDOUT->autoflush(1);
my $sock = IO::Socket::INET->new(
LocalPort => '65001',
Proto => 'tcp',
Reuse => 1,
Listen => 1,
Type => SOCK_STREAM
) || die $!;
$sock->listen();
while ( my $client = $sock->accept() )
{
if ($client)
{
$client->autoflush(1);
my $thr = threads->new(\&manage, $client);
for my $t (threads->list()) {
printf Dumper(\$t) . " has tid = %d\n", $t->tid();
}
}
}
sub manage {
my $client = shift;
my $data = <$client>;
print "$data\n";
sleep 5;
syswrite $client, "Hello World!";
close($client);
}
__END__;
now, I'd like to have all the threads killed before a new thread gets
spawnd...can it actually be done??
thanks