-
-
11 Nov 2017 23:44:01 UTC
- Distribution: IPC-Pleather
- Module version: 0.01
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (0)
- Testers (344 / 4 / 22)
- Kwalitee
Bus factor: 1- 70.73% Coverage
- License: perl_5
- Perl: v5.14.0
- Activity
24 month- Tools
- Download (12.76KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
IPC::Pleather - Easy to use concurrency primitives inspired by Cilk
VERSION
version 0.01
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; }
DESCRIPTION
C has Cilk, Perl has Pleather.
IPC::Pleather adopts two keywords from Cilk,
spawn
andsync
.spawn
signals that the block or expression may be executed concurrently.sync
denotes a merge point, waiting until the spawned expression is completely resolved.KEYWORDS
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 "SYNOPSIS") are bound by the same maximum.
The forking mechanism is implemented using "fork_call" in AnyEvent::Util, allowing the maximum number of processes to be controlled either by setting
$AnyEvent::Util::MAX_FORKS
or with thePERL_ANYEVENT_MAX_FORKS
environmental variable.spawn
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.
sync
Causes the process to block until the specified variable is fully resolved. For spawned variables which executed in a forked process, a condition variable is used to synchronize the result. When executed locally, the result is immediately assigned to the variable and the call to
sync
is essentially a no-op.SEE ALSO
AUTHOR
Jeff Ober <sysread@fastmail.fm>
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.
Module Install Instructions
To install IPC::Pleather, copy and paste the appropriate command in to your terminal.
cpanm IPC::Pleather
perl -MCPAN -e shell install IPC::Pleather
For more information on module installation, please visit the detailed CPAN module installation guide.