Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sysread/ipc-pleather

Easy to use concurrency primitives for Perl, inspired by Cilk
https://github.com/sysread/ipc-pleather

Last synced: about 1 month ago
JSON representation

Easy to use concurrency primitives for Perl, inspired by Cilk

Awesome Lists containing this project

README

        

=pod

=encoding UTF-8

=head1 NAME

IPC::Pleather - Easy to use concurrency primitives inspired by Cilk

=head1 VERSION

version 0.02

=head1 SYNOPSIS

use IPC::Pleather;

sub fib {
my $n = shift;
return $n if $n < 2;

spawn my $x = fib($n - 1);
spawn my $y = fib($n - 2);

sync $x;
sync $y;

return $x + $y;
}

=head1 DESCRIPTION

C has L, Perl has Pleather.

IPC::Pleather adopts two keywords from Cilk, C and C. C
signals that the block or expression I be executed concurrently. C
denotes a merge point, waiting until the spawned expression is completely
resolved.

=head1 KEYWORDS

=head2 spawn

Declares a variable whose value may or may not be executed in a forked process.
Some care is taken to guarantee a fixed cap on the total number of forks.
Recursive calls to spawn via the spawned expression (as in the Fibonacci
example in the L) are bound by the same maximum.

The forking mechanism is implemented using L,
allowing the maximum number of processes to be controlled either by setting
C<$AnyEvent::Util::MAX_FORKS> or with the C
environmental variable.

C accepts several different expression syntaxes.

# Block with optional arguments
spawn my $var = {...} $arg1, $arg2, $arg3;

# Subroutine call
spawn my $var = do_stuff($arg1, $arg1 + $arg2, ...);

The latter syntax expands to the former, and all expressions in the argument
list are evaluated in the subprocess (or not, as the case may be), rather than
in the process from which they were spawned.

=head2 sync

Causes the process to block until the specified variable is fully resolved.
For spawned variables which executed in a forked process, a L is used to synchronize the result. When
executed locally, the result is immediately assigned to the variable and the
call to C is essentially a no-op.

=head1 SEE ALSO

=over

=item L

=back

=head1 AUTHOR

Jeff Ober

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Jeff Ober.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut