-1
私はUnixシステムでperlで次のパターンのコードを使用しましたが、Windowsではクラッシュします。 Windows上でperlを使用してフォークするかスレッドを使用して同じことを達成するにはどうすればよいですか?ここWindowsでperlで並列プログラミングを行うには?
私はUnixシステムでperlで次のパターンのコードを使用しましたが、Windowsではクラッシュします。 Windows上でperlを使用してフォークするかスレッドを使用して同じことを達成するにはどうすればよいですか?ここWindowsでperlで並列プログラミングを行うには?
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
}
フォークを用いて一例である。
#!/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";
これは 'scalar(@all_data)'プロセスを一度に生成するため、全く同じではありません。 OPの例は、一度に '$ MAX_PROCESSES'プロセスだけを生成します。 – ThisSuitIsBlackNot
上記のコードと同等であるもの(http://p3rl.org/Thread::Queue) – choroba
[::キュースレッド] 'Thread :: Queue'を使って? – CJ7
@chorobそれもうまくいきませんでした。クラッシュします。 – CJ7