Simple(3pm)
β¨ Thread::Pool::Simple β the manual, but make it cute β¨
okay bestie, gather round, because we're talking about Thread::Pool::Simple, a Perl module living its best life in the User Contributed Perl Documentation section (that's the (3pm) energy right there π
). It's a thread-pool implementation and it is simple, hence the name, no cap.
πΈ NAME πΈ
Thread::Pool::Simple β a simple thread-pool implementation. that's it. that's the whole vibe. π«Ά
π SYNOPSIS π
okay so here's the whole thing in action, literally copy-paste core:
use Thread::Pool::Simple;
my $pool = Thread::Pool::Simple->new(
min => 3, # at least 3 workers
max => 5, # at most 5 workers
load => 10, # increase worker if on average every worker has 10 jobs waiting
init => [\&init_handle, $arg1, $arg2, ...] # run before creating worker thread
pre => [\&pre_handle, $arg1, $arg2, ...] # run after creating worker thread
do => [\&do_handle, $arg1, $arg2, ...] # job handler for each worker
post => [\&post_handle, $arg1, $arg2, ...] # run before worker threads end
passid => 1, # whether to pass the job id as the first argument to the &do_handle
lifespan => 10000, # total jobs handled by each worker
);
my ($id1) = $pool->add(@arg1); # call in list context
my $id2 = $pool->add(@arg2); # call in scalar conetxt
$pool->add(@arg3) # call in void context
my @ret = $pool->remove($id1); # get result (block)
my $ret = $pool->remove_nb($id2); # get result (no block)
$pool->cancel($id1); # cancel the job
$pool->cancel_all(); # cancel all jobs
$pool->join(); # wait till all jobs are done
$pool->detach(); # don't wait.
(yes, conetxt is in there exactly like that, we don't fix typos, we preserve history π)
π DESCRIPTION π
Thread::Pool::Simple provides a simple thread-pool implementation without external dependencies outside core modules. so like, it only uses stuff that already ships with Perl. no random CPAN chaos. it's giving self-sufficient queen π.
Jobs can be submitted to and handled by multi-threaded `workers' managed by the pool. you throw work at the pool, the pool's little worker besties handle it. teamwork makes the dream work, fr fr. β¨
π¦ AUTHOR π¦
Jianyuan Wu, <jwu@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright 2007 by Jianyuan Wu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
that's the whole page, bestie, short and iconic. this was perl v5.36.0, dated 2022-11-28, and it's the Simple(3pm) page β so go forth and pool those threads π
π
π¦ where this page comes from
- debian bookworm: libthread-pool-simple-perl 0.25-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libthread-pool-simple-perl 0.25-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libthread-pool-simple-perl 0.25-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libthread-pool-simple-perl 0.25-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libthread-pool-simple-perl 0.25-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms