MAN page from Mandrake Other perl-ThreadPool-0.1-1.i386.rpm
Pool
Section: User Contributed Perl Documentation (3)
Updated: perl 5.004, patch 04
Index NAME
Thread::Pool - worker thread pools to run Perl code asynchronously
SYNOPSIS
use Thread::Pool; my $pool = Thread::Pool->new(Min => 5, Max => 10); $pool->enqueue(\&foo, @args); $pool->set_min(7); $pool->set_max(20);
DESCRIPTION
The
Thread::Pool module implements pools of worker threads. Once athread pool is created, jobs (i.e. Perl subs with arguments) may beenqueued for the pool to execute. When a thread in the pool becomesfree, it takes another job from the pool's work queue and calls it.If a job is enqueued while no thread is free and the number of activethreads does not exceed a given maximum, a new thread is added to thepool immediately to hande the new job. A pool can be configured tohave a minimum number of threads which are always running and waitingfor jobs to carry out. A pool can be configured to have a maximumnumber of threads - only that number of threads will ever be createdin the pool and new jobs have to wait until an existing worker threadbecomes free.
METHODS
- new
- Create a new thread pool. Arguments are optional and are of the formof key/value pairs. Passing Min => $min invokes set_min($min)(q.v.) for the pool. The default min value is zero. PassingMax => $max invokes set_max($max) (q.v.) for the pool. Thedefault max value is -1.
- enqueue(CODE [, ARG, ...])
- Enqueues a new job for the pool to carry out. CODE can be a referenceto a subroutine or the name of one. Unqualified subroutine namesdefault to the caller's package. The subroutine will be called(optionally with any given arguments) in one of the worker threads inthe pool either immediately (if the number of active threads in thepool has not reached its configured maximum) or when a thread becomesfree (if it has reached its maximum).
- set_min(MIN)
- Sets the minimum number of threads in the pool to MIN. If MIN isincreased then more threads are immediately created in the pool tobring the number up to MIN. When the queue of jobs for the pool isemptied, MIN worker threads will wait around for more work ratherthan finishing.
- set_max(MAX)
- Sets the maximum number of threads in the pool to MAX meaning that nomore than MAX threads will ever be running concurrently for that pool.If MAX is -1 then the limit is infinite. That means that if a new jobis enqueued while all threads are active, a new thread is alwayscreated immediately to handle the job.
SEE ALSO
the
Thread manpage
AUTHOR
Malcolm Beattie, mbeattieAATTsable.ox.ac.uk.
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- METHODS
- SEE ALSO
- AUTHOR
This document was created byman2html,using the manual pages.