Not Exactly,
I'll be more specific:
I need to open a lot of threads with same name when passing different parameters to
each. When inside each thread there is a system call which can take a lot of time. I
want that after the system call ends the thread will close itself and remove itself
from threads->list. For example:
while(...) #here will be some condition concerned with currently running threads i.e
threads->list
$thr=new threads \&create_thread, $param;
$param=$param+1;
sub create_thread {
print("\nNew thread was started\n");
my @create_param = @_;
system("...");
print ("\nOld thread was finished\n");
}
Unfortunately this construction didn't worked because the threads->list didn't
decremented by itself after the system call was finished?
What should I do? Maybe use of "join" in some way?
THANKS A LOT
Igor
-----Original Message-----
From: zentara [mailto:[EMAIL PROTECTED]
Sent: Friday, October 10, 2003 7:44 PM
To: [EMAIL PROTECTED]
Subject: Re: threads in perl
On Wed, 8 Oct 2003 13:13:13 +0200, [EMAIL PROTECTED] (Igor
Ryaboy) wrote:
>Hi,
>I need help in simple threaded solution.
>How can I join the active thread?
>
>After I was started the thread I want him to join itself at the end and go back to
>the main
>Example:
>
># main program
>$thr1=new threads \&sub_name;
>$thr2=new threads \&sub_name;
>$thr3=new threads \&sub_name;
>$thr4=new threads \&sub_name;
>
># threaded subroutine
>sub sub_name{
> print ("\nIn the thread!\n");
> # here I need help to join this thread after the print
>
>}
>
>I need that every started thread will be killed after finished and thread->list to be
>updated
Is this what you are thinking?
#!/usr/bin/perl
use threads;
# join() does three things: it waits for a thread to exit,
# cleans up after it, and returns any data the thread may
# have produced.
$thr1 = threads->new(\&sub1);
$ReturnData1 = $thr1->join;
print "Thread1 returned @$ReturnData1\n";
$thr2 = threads->new(\&sub2);
$ReturnData2 = $thr2->join;
print "Thread2 returned @$ReturnData2\n";
$thr3 = threads->new(\&sub3);
$ReturnData3 = $thr3->join;
print "Thread3 returned @$ReturnData3\n";
sub sub1 {
@values = ('1a','1b', '1c');
return [EMAIL PROTECTED];
}
sub sub2 {
@values = ('2a','2b', '2c');
return [EMAIL PROTECTED];
}
sub sub3 {
@values = ('3a','3b', '3c');
return [EMAIL PROTECTED];
}
__END__
Our body's 20 milligrams of beta radioactive Potassium 40
emit about 340 million neutrinos per day, which go at
lightspeed to the ends of the universe!..even thru the earth.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]