2017-01-04 2 views
-1

Unix 시스템에서 perl에서 다음 패턴의 코드를 사용했지만 Windows에서 충돌합니다. Perl을 사용하여 Windows에서 포크 또는 스레드를 사용하여 동일한 작업을 수행하려면 어떻게해야합니까?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 
} 
+0

[스레드 :: 큐 (http://p3rl.org/Thread::Queue) – choroba

+0

상기 코드 등가 될지 Thread :: Queue를 사용하여? – CJ7

+0

@ choroba 그것도 작동하지 않았다. 충돌합니다. – CJ7

답변

0

여기 일례하여 포크이다

#!/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

'scalar (@all_data)'프로세스를 한꺼번에 생성하기 때문에 그렇게 똑같은 것은 아닙니다. OP의 예제는 한 번에'$ MAX_PROCESSES' 프로세스를 생성하지 않습니다. – ThisSuitIsBlackNot

관련 문제