Multithreading: Difference between revisions
Jump to navigation
Jump to search
m Created page with 'This is really cool tool * Install the Library '''Parallel::ForkManager''' through CPAN * It works only in a loop (of anykind). so make a loop if you don't have one * code as be…' |
mNo edit summary |
||
| Line 3: | Line 3: | ||
* Install the Library '''Parallel::ForkManager''' through CPAN | * Install the Library '''Parallel::ForkManager''' through CPAN | ||
* It works only in a loop (of anykind). so make a loop if you don't have one | * It works only in a loop (of anykind). so make a loop if you don't have one | ||
* | * Code as below | ||
<source lang=perl> | <source lang=perl> | ||
| Line 19: | Line 19: | ||
$i++; | $i++; | ||
$pm->start and next; | $pm->start and next; | ||
# Do your | # Do your big process. There can be sub loops here | ||
$pm->finish; | $pm->finish; | ||
} | } | ||
Latest revision as of 16:49, 8 January 2010
This is really cool tool
- Install the Library Parallel::ForkManager through CPAN
- It works only in a loop (of anykind). so make a loop if you don't have one
- Code as below
# Libraries
use Parallel::ForkManager;
# My Variables
my $pm = new Parallel::ForkManager(4); # 4 is the number of cores in your processor
# Loop
foreach my $file(@files) {
$i++;
$pm->start and next;
# Do your big process. There can be sub loops here
$pm->finish;
}
$pm->wait_all_children;
# END