Re: AW: Problem with thread

[email protected] (Thomas S Brettin)
Newsgroups perl.ithreads
Message-ID <[email protected]>
> > for ($i=1;$i<255;$i++)
> > { 
> >      $host="10.10.10."."$i";
> >      my $thread  = threads->create(threads,subping($host));
> > }
> 
> here I would say, you should write:
> my $thread1 = threads->new(\&subping, $host);
> 

So, what happens to the $thread variable in each iteration of the loop? 
Does it go out of scope and get destroyed? Normally, if something else 
references $thread, it does not get destroyed. But in this case, what 
references $thread? I'm not sure.

The code I've written code might look like this:

for ($i=1;$i<255;$i++) {
  $host="10.10.10."."$i";
  push @threads, threads->create(threads,subping($host));
}

Then somewhere else:

foreach my $thread (@threads) {
  $thread->join();
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.