thread

thread

am 08.11.2007 04:15:12 von 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

Re: thread

am 09.11.2007 19:04:42 von xhoster

Larry wrote:

....

> 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.

Re: thread

am 10.11.2007 00:18:58 von Larry

In article <20071109130443.976$QL@newsreader.com>, xhoster@gmail.com
wrote:

> 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 ...