Multi-process: With multiple PID, the memory is occupied independently.
Multi-threaded: does not have a separate PID.
Select: Multiple processes can be selected without the output of the shared variables, etc., when a partial independent generation of the results is required for a multi-threaded/process. (note independence). Multi-threaded modules can be selected when the multi-threaded part needs to return results and be aggregated (not completely independent).
Multi-Process Package:Parallel::forkmanager
Usage examples:
Use Parallel::forkmanager; My [email protected];
My $pm = parallel::forkmanager->new ($Threshold 1);foreach my $sample (@sample) {
$pm->start and next;Sub ();
$pm->finish;}
$pm->wait_all_children;Example 2 No Package
my $count = 0;
foreach my $sample (keys%hash) {
$count + +;
my $pid = fork;
if ($pid = = 0) {
{sub ()};
Exit
}
if ($count = = $Thread _num) {
my $pid = waitpid-1,0;
$count--if $pid > 0;
}
}
while (My $pid = Waitpid ( -1,0) > 0) {}
Multi-threading and multi-process for Perl