JamesNC has asked for the wisdom of the Perl Monks concerning the following question:
Ok, the problem is that if I join in the block where the threads get created... it waits for each process to finish. If I join after the create threads... it works... BUT ONLY IF all the threads finish in order... And, if I don't join at all... I don't get anything I have tried the async method, and got the same results. Are all the threads dependant on each other? If you have to wait on each thread to finish... what is the use in threads?use threads; use threads::shared; use strict; my $wait = 500; my @up: shared; my $th; my @down: shared; my @list = qw ( www.apple.com www.perl.org www.ibm.com www.coke.com ww +w.oracle.com www.hp.com ); foreach(@list){ $th = threads->create("ping","$_"); # $th->join; # new thread is NOT created until join # not what I want! } # This works... unless one of the threads finishes too # soon... then the app dies... $th->join; print @up; print @down; sub ping { my $ip = shift; my @rv = `ping -n 1 -w $wait $ip`; foreach(@rv){ push @up, "$ip up\n" if /\(0% loss\)/; push @down, "$ip down\n" if /\(100% loss\)/; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using threads with Ping
by pg (Canon) on Jan 31, 2003 at 04:50 UTC | |
by JamesNC (Chaplain) on Jan 31, 2003 at 05:16 UTC | |
|
Re: Using threads with Ping
by submersible_toaster (Chaplain) on Jan 31, 2003 at 06:28 UTC | |
|
Re: Using threads with Ping
by derby (Abbot) on Jan 31, 2003 at 13:55 UTC | |
by JamesNC (Chaplain) on Jan 31, 2003 at 15:21 UTC |