Parallel::Queue is a Perl module to fork or thread a list of closures N-way parallel.
SYNOPSIS
# example queue:
# only squish files larger than 8KB in size. figure
# that the system can handle four copies of squish
# running at the same time without them interfering
# with one another.
my @queue = map { -s > 8192 ? sub{ squish $_ } : () } @filz;
# functional: pass in the count and list of coderefs.
#
# adding 'runqueue' exports the subroutine into
# the current package. useful for non-OO situations.
#
# run the queue 4 way parallel.
use Parallel::Queue qw( runqueue verbose fork );
my @remaining = runqueue 4, @queue;
die "Incomplete jobs" if @remaining;
# OO: generate queue manager and use without the
# 'runqueue' arguments, construct a queue manager,
# and use it to run the jobs
use Parallel::Queue;
my $quemgr = Parallel::Queue->construct( thread );
$quemgr->runqueue( 4, @queue );
die "Incomplete jobs" if @queue;
# call Parallel::Queue with the default configuration
# (fork quietly).
require Parallel::Queue;
Parallel::Queue->runqueue( 4, @queue );
# pre-define defaults for the objects: leave
# out runqueue, set the rest, and construct
# an object. the one here gets verbose, thread,
# and debug all set to true.
use Parallel::Queue qw( verbose thread );
my $quemgr = Parallel::Queue->construct( debug );
my @remaining = $quemgr->runqueue( 4, @queue );
Given a count and an array of coderefs (most likely closures), runqueue will run the jobs in parallel. The jobs can be run via fork or detached threads [see known issues for threading]. Jobs on the queue are executed until one of them exits non-zero, the fork/thread operation fails, or all of them are dispatched (i.e., the queue is empty).
Product's homepage
Requirements:
· Perl