Thread::Task::Concurrent - Make simple task pocessing simple
use Thread::Task::Concurrent qw(tmsg); my @data = qw(a b c d e f g h i j k l m n o p q); my $tq = Thread::Task::Concurrent->new( task => \&task, max_instances => 4, verbose => 1 ); my $result = $tq->enqueue(@data)->start->join->result; sub task { my $char = shift; # sleep some time my $sleep_time = int rand 10; sleep $sleep_time; #calculate result my $result = "I'm thread " . threads->tid . " and I slept $sleep_time sec. My result was " . $char x 3; return $result; }
If you have input data and you want to pocess it in the same way, Thread::Task::Concurrent gives you an easy to use interface to getthingsdone(TM).
Spits out the $string_message in the form:
$string_message
[thread_id] <message>
thread_id is by default threads->tid, but you can also set it artificially via the $tid_to_display variable.
threads->tid
$tid_to_display
Set the subroutine for the task. Example:
sub { my ($item, $task_arg) = @_; return $result_item; }
Add an additional arg hash/array/scalar to the task/subroutine call.
Set the maximum number of threads. Default is 4.
Switch on/off verbose reporting.
Start processing.
Wait for processing end.
Enqueue items.
Gather the result.
-
jw bargsten, <cpan at bargsten dot org>
<cpan at bargsten dot org>
To install Thread::Task::Concurrent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Thread::Task::Concurrent
CPAN shell
perl -MCPAN -e shell install Thread::Task::Concurrent
For more information on module installation, please visit the detailed CPAN module installation guide.