threads::lite(3pm)
π threads::lite β the perl manual page (3pm) π
okay bestie, gather round, because this is threads::lite and it's literally Actor model threading for Perl. π«Ά
β¨ VERSION β¨
This is Version 0.034. Yes, a real number. Write it down. π
πΈ SYNOPSIS πΈ
here's the whole vibe in code form, no edits, no cap:
use Modern::Perl;
use threads::lite qw/spawn self receive receive_table/;
use SmartMatch::Sugar;
sub child {
my $other = threads::lite::receiveq;
while (<>) {
chomp;
$other->send(line => $_);
}
return;
}
my $child = spawn({ monitor => 1 } , \&child);
$child->send(self);
my $continue = 1;
while ($continue) {
receive {
when([ 'line', any ]) {
my (undef, $line) = @$_;
say "received line: $line";
}
when([ 'exit', any, $child->id ]) {
say "received end of file";
$continue = 0;
}
default {
die sprintf "Got unknown message: (%s)", join ", ", @$_;
}
};
};
π¦ DESCRIPTION π¦
So this module implements threads for perl. Slay. But here's the one crucial difference from "threads.pm" threads: these threads are disconnected, except by message queues. That's it, that's the whole relationship β they only talk through the mail. π It thus facilitates a message passing style of multi-threading. very demure, very mindful, very mailbox-core.
β οΈ okay real talk bestie, listen up: this module is a research project. In no way is API stability guaranteed. It is released for evaluation purposes only, not for production usage. Do NOT put this in prod, I am begging you. π
π FUNCTIONS π
All these functions are exported optionally β so you gotta ask for them, they're not just gonna show up uninvited.
π Utility functions
spawn($options, $sub)β Spawn new threads. It will run$suband send all monitoring processes it's return value.$optionsis a hashref that can contain the following elements:modules => [...]β Load the specified modules before running any code.pool_size => intβ Createpool_sizeidentical clones. π―monitor => 0/1β If this is true, the calling process will monitor the newly spawned threads. Defaults to false.stack_size => intβ The stack size for the newly created threads. It defaults to 64 kiB.
$sub can be a function name or a subref. If it is a name, you must make sure the module it is in is loaded in the new thread. If it is a reference to a function it will be serialized before being sent to the new thread. This means that any enclosed variables will probability not work as expected. π Any locally imported functions will not be defined in the new thread, so you probably want to use fully qualified names. fr fr, save yourself the heartbreak.
self()β Retreive the thread identifier object corresponding with the current thread. it's giving main character energy but for your thread. πsend_to($id, ...)β Send a message a thread identified by its primitive identifier.
π§ Receiving functions
All these functions will try to match messages in the local thread's mailbox to a pattern. If it can find a match, the message will be removed from the mailbox. one match, one message, gone. β¨
receive { ... }β Match each message against the code in the block until a message matches it. The block is expected to contain"when"and"default"blocks, but may contain other code too. If no matching message is found, it will block until a suitable message is received. patience is a virtue bestie. π§receive_nb { ... }β Match in exactly the same way receive does, but do not block if no suitable message can be found. Instead it will return an empty list. thenbstands for no-blocking, iykyk. πreceiveq(@pattern)β Return the first message that smart-matches@pattern. If there is no such message in the queue, it blocks until a suitable message is received. An empty pattern results in the first message.receiveq_nb(@pattern)β Return the first message that smart-matches@pattern. If there is no such message in the queue, it returns an empty list (undefin scalar context).
π AUTHOR π
Leon Timmermans, "<leont at cpan.org>" β the icon, the legend, the one who did this. π
π BUGS π
This is an early development release, and is expected to be buggy and incomplete. In particular, memory management is known to be buggy. not me reading that and still using it. π
Please report any bugs or feature requests to "bug-threads-lite at rt.cpan.org", or through the web interface at:
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=threads-lite
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. bestie accountability system, we love to see it. π«Ά
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc threads::lite
You can also look for information at:
- RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=threads-lite
- AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/threads-lite
- CPAN Ratings
http://cpanratings.perl.org/d/threads-lite
- Search CPAN
http://search.cpan.org/dist/threads-lite
π COPYRIGHT & LICENSE π
Copyright 2009, 2010, 2011 Leon Timmermans, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay and that's the whole page bestie!! this was threads::lite manual page, version perl v5.42.0, dated 2025-07-25 β mwah, iconic, go build something chaotic with it (just not in production π
β¨).
π¦ where this page comes from
- fedora 43: perl-threads-lite 0.034-39.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms