subs::parallel

subs::parallel is a Perl module which enables subroutines to seamlessly run in parallel.
Download

subs::parallel Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Nilson Santos F. Jr.
  • Publisher web site:
  • http://search.cpan.org/~nilsonsfj/subs-parallel-0.08/lib/subs/parallel.pm

subs::parallel Tags


subs::parallel Description

subs::parallel is a Perl module which enables subroutines to seamlessly run in parallel. subs::parallel is a Perl module which enables subroutines to seamlessly run in parallel.SYNOPSIS use subs::parallel; sub foo : Parallel { # foo runs in parallel } parallelize_sub('bar'); # subroutine named bar now runs in parallel my $foo = foo(); # returns immediately my $bar = bar(); # also returns immediately # now it might block waiting for both to finish if ($foo == $bar) { ... } my $baz = parallelize { ... code ... }; # returns immediately ... print "baz: $bazn"; # if it's still running, blocks until it finishes # it can be done to anonymous subs or any other coderefs too my $anon = sub { ... more code ... }; my $parallel_coderef = parallelize_coderef($anon); my $foobar = $parallel_coderef->('arg'); # returns immediately ... # sub should return an object, no problem $foobar->do_something_else(); # blocks until it finishes runningThis module gives Perl programmers the ability to easily and conveniently create multi-threaded applications through parallel subroutines.Parallel subroutines are just plain old subroutines which happen to run in another thread. When called, they return immediately to the calling thread but keep running in another. When its return value is needed somewhere, the returned value is transparently fetched. If the thread is still running, the code blocks waiting for it to finish (since the program can't go on without a value and keep being transparent).So, as it's possible to notice, the module interface aims to be as simple as possible. In fact, it works in such a way that, aside from the parallelizing directives, you wouldn't be able to tell it's a multi-threaded application. All the thread handling (which isn't that complicated, really) is done automagically.It should work for anything that's thread safe - even for subroutines whose return values are not usually available across thread boundaries (for example, usually, you can't share an object, but this module makes it possible to return them without any problems, provided they're thread safe). Requirements: · Perl


subs::parallel Related Software