in reply to Re: Multi threading
in thread Multi threading
#!/usr/bin/perl use Parallel::ForkManager; my $processor = shift; $tc=5; # threads $fc = 100; # splits.. each thread should process 100 at a time my $pm = new Parallel::ForkManager($tc+1); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; $tmp +Files[$ident] = undef; } ); foreach my $i (0..$#tmpFiles) { # Forks and returns the pid for the child: my $pid = $pm->start($i) and next; $SIG{INT} = 'DEFAULT'; my $filename = $tmpFiles[$i]->filename(); my $file = IO::File->new("<$filename") or die "Can't open $filen +ame\n"; while((my $line) = $file->getline()) { last unless defined($line); chomp $line; my ($dir, $file) = split(/\t/, $line); $processor->($dir, $file, $config, $log); } $pm->finish; # Terminates the child process }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Multi threading
by cdarke (Prior) on Apr 06, 2009 at 07:55 UTC | |
by sandy1028 (Sexton) on Apr 06, 2009 at 09:15 UTC | |
by shoness (Friar) on Apr 06, 2009 at 19:23 UTC | |
|
Re^3: Multi threading
by sandy1028 (Sexton) on Apr 07, 2009 at 10:05 UTC |