gants has asked for the wisdom of the Perl Monks concerning the following question:
use threads; my %queue; file_watchdog(); exit 1; sub file_watchdog { open(TRAP, '<tst.log') or die "can't open file_watchdog!"; while (1) { select(undef,undef,undef,0.2); my $a .= <TRAP>; if(length($a) gt 0 ){ checker($a); } } close (TRAP); } sub checker { my ($y) = @_; if($y =~ /(\d+)\-(\d+)\-(\d+)\-(\d+)/){ my $ip =$1; my $idx= $2; my $time = $3; my $th = $4; my $thr_h; $queue{$ip}{$idx}{TICK} = $time; if($time < 5 ){ my $wait = 7-$time; $queue{$ip}{$idx}{WAIT} = $wait; print "IP:$ip IDX:$idx TIME:$time TH:$th WAIT:$wait \n"; if($th){ #Thread 2 terminated abnormally: Not a CODE reference + at thread.pl line 34, <TRAP> line 2. $thr_h->{$ip} = threads->create(\&wait_q($ip,$idx)); #->join() +; }else{ wait_q($ip,$idx); } }else{ if ($thr_h->{$ip}->is_joinable()) {#Can't call method "is_join +able" on an undefined value at thread.pl line 40, <TRAP> line 3. $thr_h->{$ip}->join(); } print "do_connection() IP:$ip\n"; } } } sub wait_q { my $ip = shift; my $idx = shift; sleep( $queue{$ip}{$idx}{WAIT} ); oid_checker($ip); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: threads join()
by zentara (Cardinal) on Oct 30, 2009 at 11:38 UTC | |
|
Re: threads join()
by llancet (Friar) on Oct 30, 2009 at 14:41 UTC |