2017-01-04 7 views
-1

Ich habe das folgende Muster von Code in Perl auf einem Unix-System verwendet, aber es stürzt unter Windows ab. Wie kann ich dasselbe erreichen, indem ich mit Windows Perl oder Fork unter Windows verwende?Parallele Programmierung in Perl unter Windows?

use Parallel::ForkManager; 

my $pm = Parallel::ForkManager->new($MAX_PROCESSES); 

DATA_LOOP: 
foreach my $data (@all_data) { 
    # Forks and returns the pid for the child: 
    my $pid = $pm->start and next DATA_LOOP; 

    # ... do some work with $data in the child process ... 

    $pm->finish; # Terminates the child process 
} 
+0

[Thema :: Queue] (http://p3rl.org/Thread::Queue) – choroba

+0

Was entspricht dem obigen Code würde mit 'Thread :: Warteschlange '? – CJ7

+0

@choroba Es hat auch nicht funktioniert. Stürzt auch ab. – CJ7

Antwort

0

Hier ist ein Beispiel mit Gabel:

#!/usr/bin/perl -w 
use strict; 


foreach my $data (@all_data) { 
    my $pid; 
    next if $pid = fork; # Parent goes to next server. 
    die "fork failed: $!" unless defined $pid; 

    # From here on, we're in the child. Do whatever the 
    # child has to do... The server we want to deal 
    # with is in $data. 

    exit; # Ends the child process. 
} 

# The following waits until all child processes have 
# finished, before allowing the parent to die. 

1 while (wait() != -1); 

print "All done!\n"; 
+1

Das ist nicht ganz dasselbe, weil es 'skalare (@all_data)' -Prozesse auf einmal erzeugt. Das Beispiel des OP erzeugt nicht mehr als $ MAX_PROCESSES Prozesse gleichzeitig. – ThisSuitIsBlackNot