thread

L

Larry

Hi 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
 
X

xhoster

....
now, I'd like to have all the threads killed before a new thread gets
spawnd...can it actually be done??

I don't know if it can be done, but if you only want to have one thread
running at a time (well, two, one that is doing stuff and one that is
killing off the one that is doing stuff), why use threads in the first
place?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
L

Larry

I don't know if it can be done, but if you only want to have one thread
running at a time (well, two, one that is doing stuff and one that is
killing off the one that is doing stuff), why use threads in the first
place?

I cannot wait for others threads to finish ... anyway ... I need to get
control of <STDIN> ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top