Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > thread

Reply
Thread Tools

thread

 
 
Larry
Guest
Posts: n/a
 
      11-08-2007
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:umper;
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
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      11-09-2007
Larry <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Larry
Guest
Posts: n/a
 
      11-09-2007
In article <20071109130443.976$(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
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 <STDIN> ...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Terminating a thread from the main thread Charles A. Lackman ASP .Net 3 12-09-2004 02:12 PM
Thread was being aborted thrown for background thread (win2003 ser =?Utf-8?B?Sm9oYW5uYQ==?= ASP .Net 3 10-15-2004 01:35 PM
Thread was being aborted in win2003 server. Back ground thread reading MS access database, no redirects or transfers. Johanna ASP .Net 0 10-13-2004 01:32 PM
"Thread was being aborted" error from WebApp using Thread.Sleep. Stephen Miller ASP .Net 3 07-01-2004 11:50 PM
perl 5.8.2/3 - thread started by a thread pawo Perl 0 02-16-2004 01:18 PM



Advertisments