NAME
Thread::Csp - Communicating sequential processes threading for Perl
VERSION
version 0.009
SYNOPSIS
# in script.pl
use Thread::Csp;
my $input = Thread::Csp::Channel->new;
my $output = Thread::Csp::Channel->new;
Thread::Csp->spawn('Module', 'Module::function', $input, $output);
while (<>) {
$input->send($_);
print $output->receive;
}
$input->send(undef);
# in Module.pm
package Module;
sub function {
my ($input, $output) = @_;
while (defined(my $entry = $input->receive)) {
$output->send(2 * $entry);
}
}
1;
DESCRIPTION
This module implements share-nothing threads for perl. One crucial difference with threads.pm
threads is that the original thread will not be cloned except for the arguments that you pass on thread creation. Thread::Csp::Channels (also using cloning to get values across) are used for inter-thread communication; one or more channels will nearly always be such creation arguments.
Please note that at this stage this module is a research project. In no way is API stability guaranteed. It is released for evaluation purposes only, not for production usage.
METHODS
spawn($module, $sub, @args)
Spawn a new thread. It will load $module and then run $sub
(fully-qualified function name) with @args
as arguments. It returns a Thread::Csp::Promise that will finish when the thread is finished.
AUTHOR
Leon Timmermans <leont@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.