On Thu, 2008-04-24 at 17:06 -0700, Wong, Danny H. wrote:
> Thanks for your comments. Do you have a perl example on how it can be
> done? I've read comments like yours on the websites, but don't have a
> concrete example.  I'm trying to figure out how to implement a copy
> function with work crew thread model. I'm learning how to use the
> power
> of threads and of course using it correctly...

Honestly I've not worked in perl threads in a long time.  I got started
and ran into so many obstacles learning about interpreter threads vs
<flamebait>real threads</flamebait> that I gave up.  I'm hoping that
Parrot may do <flamebait>the right thing(tm)</flamebait> and implement
some real threads.

Here is a ROUGH simple example


use Net::Ping;
use threads;

sub worker {
  my $target = shift;

  while(1) {
    my $p = Net::Ping->new();
    my $r = $p->ping($target, 5);
    if($r == 0) {
      print "$target:DOWN\n"; 
    } else {
      print "$target:UP\n";

    }

    $p->close();

  }
}


# main program


pipe R,W;

for(my $x = 1; $x <= 10; $x++) {
  threads->create("worker", "192.168.7.$x");
}

while(<R>) {
  print "$_"; 
}


I use pipes (IPC) for the workers to talk back to the manager.
You can replace thread with fork and still use this method.  The program
is not smart enough to track changes in state, etc.  That logic can go
in the workers or the manager.

Chris



Reply via email to