diff --git a/Changes b/Changes index 33dcb7b..1aab034 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,14 @@ Revision history for Perl module MCE. +1.897 Wed Jun 19 22:00:00 EST 2024 + + * In scalar context, the init function in MCE Child and models Flow, Grep, + Loop, Map, Step, and Stream returns a guard to call finish automatically + upon leaving the { scope i.e. omitting finish }. + + * Add out_iter_callback to MCE::Candy. + 1.896 Tue Jun 11 16:00:00 EST 2024 * Weaken internal core MCE reference to reap workers automatically diff --git a/MANIFEST b/MANIFEST index 573237b..3d64e6b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -80,6 +80,7 @@ t/05_mce_loop.t t/05_mce_map.t t/05_mce_step.t t/05_mce_stream.t +t/06_candy.t t/06_nodata_flow.t t/06_nodata_step.t t/06_relay.t diff --git a/META.json b/META.json index dfd2906..d236113 100644 --- a/META.json +++ b/META.json @@ -65,135 +65,135 @@ "provides" : { "MCE" : { "file" : "lib/MCE.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Candy" : { "file" : "lib/MCE/Candy.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Channel" : { "file" : "lib/MCE/Channel.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Channel::Mutex" : { "file" : "lib/MCE/Channel/Mutex.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Channel::MutexFast" : { "file" : "lib/MCE/Channel/MutexFast.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Channel::Simple" : { "file" : "lib/MCE/Channel/Simple.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Channel::SimpleFast" : { "file" : "lib/MCE/Channel/SimpleFast.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Channel::Threads" : { "file" : "lib/MCE/Channel/Threads.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Channel::ThreadsFast" : { "file" : "lib/MCE/Channel/ThreadsFast.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Child" : { "file" : "lib/MCE/Child.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Input::Generator" : { "file" : "lib/MCE/Core/Input/Generator.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Input::Handle" : { "file" : "lib/MCE/Core/Input/Handle.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Input::Iterator" : { "file" : "lib/MCE/Core/Input/Iterator.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Input::Request" : { "file" : "lib/MCE/Core/Input/Request.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Input::Sequence" : { "file" : "lib/MCE/Core/Input/Sequence.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Manager" : { "file" : "lib/MCE/Core/Manager.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Validation" : { "file" : "lib/MCE/Core/Validation.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Core::Worker" : { "file" : "lib/MCE/Core/Worker.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Flow" : { "file" : "lib/MCE/Flow.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Grep" : { "file" : "lib/MCE/Grep.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Loop" : { "file" : "lib/MCE/Loop.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Map" : { "file" : "lib/MCE/Map.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Mutex" : { "file" : "lib/MCE/Mutex.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Mutex::Channel" : { "file" : "lib/MCE/Mutex/Channel.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Mutex::Channel2" : { "file" : "lib/MCE/Mutex/Channel2.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Mutex::Flock" : { "file" : "lib/MCE/Mutex/Flock.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Queue" : { "file" : "lib/MCE/Queue.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Relay" : { "file" : "lib/MCE/Relay.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Signal" : { "file" : "lib/MCE/Signal.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Step" : { "file" : "lib/MCE/Step.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Stream" : { "file" : "lib/MCE/Stream.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Subs" : { "file" : "lib/MCE/Subs.pm", - "version" : "1.896" + "version" : "1.897" }, "MCE::Util" : { "file" : "lib/MCE/Util.pm", - "version" : "1.896" + "version" : "1.897" } }, "release_status" : "stable", @@ -209,5 +209,5 @@ "url" : "https://github.com/marioroy/mce-perl.git" } }, - "version" : "1.896" + "version" : "1.897" } diff --git a/META.yml b/META.yml index 92fbfa4..e817ff0 100644 --- a/META.yml +++ b/META.yml @@ -25,103 +25,103 @@ no_index: provides: MCE: file: lib/MCE.pm - version: '1.896' + version: '1.897' MCE::Candy: file: lib/MCE/Candy.pm - version: '1.896' + version: '1.897' MCE::Channel: file: lib/MCE/Channel.pm - version: '1.896' + version: '1.897' MCE::Channel::Mutex: file: lib/MCE/Channel/Mutex.pm - version: '1.896' + version: '1.897' MCE::Channel::MutexFast: file: lib/MCE/Channel/MutexFast.pm - version: '1.896' + version: '1.897' MCE::Channel::Simple: file: lib/MCE/Channel/Simple.pm - version: '1.896' + version: '1.897' MCE::Channel::SimpleFast: file: lib/MCE/Channel/SimpleFast.pm - version: '1.896' + version: '1.897' MCE::Channel::Threads: file: lib/MCE/Channel/Threads.pm - version: '1.896' + version: '1.897' MCE::Channel::ThreadsFast: file: lib/MCE/Channel/ThreadsFast.pm - version: '1.896' + version: '1.897' MCE::Child: file: lib/MCE/Child.pm - version: '1.896' + version: '1.897' MCE::Core::Input::Generator: file: lib/MCE/Core/Input/Generator.pm - version: '1.896' + version: '1.897' MCE::Core::Input::Handle: file: lib/MCE/Core/Input/Handle.pm - version: '1.896' + version: '1.897' MCE::Core::Input::Iterator: file: lib/MCE/Core/Input/Iterator.pm - version: '1.896' + version: '1.897' MCE::Core::Input::Request: file: lib/MCE/Core/Input/Request.pm - version: '1.896' + version: '1.897' MCE::Core::Input::Sequence: file: lib/MCE/Core/Input/Sequence.pm - version: '1.896' + version: '1.897' MCE::Core::Manager: file: lib/MCE/Core/Manager.pm - version: '1.896' + version: '1.897' MCE::Core::Validation: file: lib/MCE/Core/Validation.pm - version: '1.896' + version: '1.897' MCE::Core::Worker: file: lib/MCE/Core/Worker.pm - version: '1.896' + version: '1.897' MCE::Flow: file: lib/MCE/Flow.pm - version: '1.896' + version: '1.897' MCE::Grep: file: lib/MCE/Grep.pm - version: '1.896' + version: '1.897' MCE::Loop: file: lib/MCE/Loop.pm - version: '1.896' + version: '1.897' MCE::Map: file: lib/MCE/Map.pm - version: '1.896' + version: '1.897' MCE::Mutex: file: lib/MCE/Mutex.pm - version: '1.896' + version: '1.897' MCE::Mutex::Channel: file: lib/MCE/Mutex/Channel.pm - version: '1.896' + version: '1.897' MCE::Mutex::Channel2: file: lib/MCE/Mutex/Channel2.pm - version: '1.896' + version: '1.897' MCE::Mutex::Flock: file: lib/MCE/Mutex/Flock.pm - version: '1.896' + version: '1.897' MCE::Queue: file: lib/MCE/Queue.pm - version: '1.896' + version: '1.897' MCE::Relay: file: lib/MCE/Relay.pm - version: '1.896' + version: '1.897' MCE::Signal: file: lib/MCE/Signal.pm - version: '1.896' + version: '1.897' MCE::Step: file: lib/MCE/Step.pm - version: '1.896' + version: '1.897' MCE::Stream: file: lib/MCE/Stream.pm - version: '1.896' + version: '1.897' MCE::Subs: file: lib/MCE/Subs.pm - version: '1.896' + version: '1.897' MCE::Util: file: lib/MCE/Util.pm - version: '1.896' + version: '1.897' recommends: Sereal::Decoder: '3.015' Sereal::Encoder: '3.015' @@ -148,4 +148,4 @@ resources: homepage: https://github.com/marioroy/mce-perl license: https://dev.perl.org/licenses/ repository: https://github.com/marioroy/mce-perl.git -version: '1.896' +version: '1.897' diff --git a/Makefile.PL b/Makefile.PL index e1fe74f..38a037e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -17,7 +17,7 @@ WriteMakefile( ABSTRACT => 'Many-Core Engine for Perl providing parallel processing capabilities', AUTHOR => 'Mario E. Roy ', NAME => 'MCE', - VERSION => '1.896', + VERSION => '1.897', EXE_FILES => [ @exe_files ], @@ -68,135 +68,135 @@ WriteMakefile( 'provides' => { 'MCE' => { 'file' => 'lib/MCE.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Candy' => { 'file' => 'lib/MCE/Candy.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Channel' => { 'file' => 'lib/MCE/Channel.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Channel::Mutex' => { 'file' => 'lib/MCE/Channel/Mutex.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Channel::MutexFast' => { 'file' => 'lib/MCE/Channel/MutexFast.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Channel::Simple' => { 'file' => 'lib/MCE/Channel/Simple.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Channel::SimpleFast' => { 'file' => 'lib/MCE/Channel/SimpleFast.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Channel::Threads' => { 'file' => 'lib/MCE/Channel/Threads.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Channel::ThreadsFast' => { 'file' => 'lib/MCE/Channel/ThreadsFast.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Child' => { 'file' => 'lib/MCE/Child.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Input::Generator' => { 'file' => 'lib/MCE/Core/Input/Generator.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Input::Handle' => { 'file' => 'lib/MCE/Core/Input/Handle.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Input::Iterator' => { 'file' => 'lib/MCE/Core/Input/Iterator.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Input::Request' => { 'file' => 'lib/MCE/Core/Input/Request.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Input::Sequence' => { 'file' => 'lib/MCE/Core/Input/Sequence.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Manager' => { 'file' => 'lib/MCE/Core/Manager.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Validation' => { 'file' => 'lib/MCE/Core/Validation.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Core::Worker' => { 'file' => 'lib/MCE/Core/Worker.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Flow' => { 'file' => 'lib/MCE/Flow.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Grep' => { 'file' => 'lib/MCE/Grep.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Loop' => { 'file' => 'lib/MCE/Loop.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Map' => { 'file' => 'lib/MCE/Map.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Mutex' => { 'file' => 'lib/MCE/Mutex.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Mutex::Channel' => { 'file' => 'lib/MCE/Mutex/Channel.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Mutex::Channel2' => { 'file' => 'lib/MCE/Mutex/Channel2.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Mutex::Flock' => { 'file' => 'lib/MCE/Mutex/Flock.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Queue' => { 'file' => 'lib/MCE/Queue.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Relay' => { 'file' => 'lib/MCE/Relay.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Signal' => { 'file' => 'lib/MCE/Signal.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Step' => { 'file' => 'lib/MCE/Step.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Stream' => { 'file' => 'lib/MCE/Stream.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Subs' => { 'file' => 'lib/MCE/Subs.pm', - 'version' => '1.896' + 'version' => '1.897' }, 'MCE::Util' => { 'file' => 'lib/MCE/Util.pm', - 'version' => '1.896' + 'version' => '1.897' } }, 'prereqs' => { diff --git a/README.md b/README.md index 733c03c..09a2677 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Many-Core Engine for Perl -This document describes MCE version 1.896. +This document describes MCE version 1.897. Many-Core Engine (MCE) for Perl helps enable a new level of performance by maximizing all available cores. diff --git a/lib/MCE.pm b/lib/MCE.pm index a39dfd0..6c9df18 100644 --- a/lib/MCE.pm +++ b/lib/MCE.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) diff --git a/lib/MCE.pod b/lib/MCE.pod index 38f46cc..2b4fe04 100644 --- a/lib/MCE.pod +++ b/lib/MCE.pod @@ -5,7 +5,7 @@ MCE - Many-Core Engine for Perl providing parallel processing capabilities =head1 VERSION -This document describes MCE version 1.896 +This document describes MCE version 1.897 Many-Core Engine (MCE) for Perl helps enable a new level of performance by maximizing all available cores. diff --git a/lib/MCE/Candy.pm b/lib/MCE/Candy.pm index 51eeccc..5c431c2 100644 --- a/lib/MCE/Candy.pm +++ b/lib/MCE/Candy.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; our @CARP_NOT = qw( MCE ); @@ -176,6 +176,32 @@ sub out_iter_array { }; } +sub out_iter_callback { + + my $_cref = shift; my %_tmp; my $_order_id = 1; + + MCE::_croak('The argument to (out_iter_callback) is not a CODE ref.') + unless (ref $_cref eq 'CODE'); + + return sub { + my $_chunk_id = shift; + + if ($_chunk_id == $_order_id && keys %_tmp == 0) { + ## already orderly + $_order_id++, $_cref->(@_); + } + else { + ## hold temporarily otherwise until orderly + @{ $_tmp{ $_chunk_id } } = @_; + + while (1) { + last unless exists $_tmp{ $_order_id }; + $_cref->(@{ delete $_tmp{ $_order_id++ } }); + } + } + }; +} + sub out_iter_fh { my $_fh = $_[0]; my %_tmp; my $_order_id = 1; @@ -240,7 +266,7 @@ MCE::Candy - Sugar methods and output iterators =head1 VERSION -This document describes MCE::Candy version 1.896 +This document describes MCE::Candy version 1.897 =head1 DESCRIPTION @@ -340,10 +366,9 @@ to 1 when not specified. =head1 OUTPUT ITERATORS WITH INPUT -This module includes 2 output iterators which are useful for preserving output -order while gathering data. These cover the 2 general use cases. The chunk_id -value must be the first argument to gather. Gather must also not be called -more than once inside the block. +This module provides three output iterators useful for preserving output order +while gathering data. The chunk_id value must be the first argument to gather. +Gather must be called once and not more inside the block. =head2 gather => MCE::Candy::out_iter_array( \@array ) @@ -365,6 +390,7 @@ chunk_size to 1. ); $mce->process([ 100 .. 109 ]); + $mce->shutdown(); print "@results", "\n"; @@ -394,12 +420,56 @@ to reduce the overhead placed on IPC. ); $mce->process([ 100_000 .. 200_000 - 1 ]); + $mce->shutdown(); + + print scalar @results, "\n"; + + -- Output + + 100000 + +=head2 gather => MCE::Candy::out_iter_callback( \&cb_func ) + +MCE workers pass arguments for the callback function. The chunk_id argument +to gather is used internally for calling the callback function orderly. + +Current API available since 1.897. + + use MCE; + use MCE::Candy; + + my @results; + my $max_status = 0; + + sub upd_vars { + push @results, @{ $_[0] }; + $max_status = $_[1] if ($_[1] > $max_status); + } + + my $mce = MCE->new( + chunk_size => 100, max_workers => 4, + gather => MCE::Candy::out_iter_callback(\&upd_vars), + user_func => sub { + my ($mce, $chunk_ref, $chunk_id) = @_; + my @output; + foreach my $item (@{ $chunk_ref }) { + push @output, $item * 2; + } + my $status = $mce->chunk_id == 3 ? 2 : 0; + $mce->gather($chunk_id, [ @output ], $status); + } + ); + + $mce->process([ 100_000 .. 200_000 - 1 ]); + $mce->shutdown(); print scalar @results, "\n"; + print $max_status, "\n"; -- Output 100000 + 2 =head2 gather => MCE::Candy::out_iter_fh( $fh ) @@ -502,20 +572,27 @@ Chunking is desired for the next example due to processing many thousands. =head1 OUTPUT ITERATORS WITHOUT INPUT -Input data is not a requirement for using the output iterators included in this -module. The 'chunk_id' value is set uniquely and the same as 'wid' when not +Input data is not a requirement for using the output iterators. The 'chunk_id' +argument to gather is still needed and set uniquely, same as 'wid' when not processing input data. =head2 gather => MCE::Candy::out_iter_array( \@array ) +=head2 gather => MCE::Candy::out_iter_callback( \&cb_func ) + use MCE::Flow; use MCE::Candy; my @results; + sub append_results { + push @results, $_[0]; + } + mce_flow { max_workers => 'auto', ## Note that 'auto' is never greater than 8 - gather => MCE::Candy::out_iter_array(\@results) + gather => MCE::Candy::out_iter_array(\@results), + # gather => MCE::Candy::out_iter_callback(\&append_results), }, sub { my ($mce) = @_; ## This line is not necessary @@ -524,7 +601,7 @@ processing input data. ## Sending a complex data structure is allowed ## Output will become orderly by iterator - $mce->gather( $mce->chunk_id, { + $mce->gather( $mce->wid, { wid => $mce->wid, result => $mce->wid * 2 }); }; diff --git a/lib/MCE/Channel.pm b/lib/MCE/Channel.pm index 9cef267..12b729b 100644 --- a/lib/MCE/Channel.pm +++ b/lib/MCE/Channel.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -131,7 +131,7 @@ MCE::Channel - Queue-like and two-way communication capability =head1 VERSION -This document describes MCE::Channel version 1.896 +This document describes MCE::Channel version 1.897 =head1 SYNOPSIS diff --git a/lib/MCE/Channel/Mutex.pm b/lib/MCE/Channel/Mutex.pm index 97ca857..41790bd 100644 --- a/lib/MCE/Channel/Mutex.pm +++ b/lib/MCE/Channel/Mutex.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use base 'MCE::Channel'; use MCE::Mutex (); @@ -296,7 +296,7 @@ MCE::Channel::Mutex - Channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::Mutex version 1.896 +This document describes MCE::Channel::Mutex version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/MutexFast.pm b/lib/MCE/Channel/MutexFast.pm index bc5b103..0ec5514 100644 --- a/lib/MCE/Channel/MutexFast.pm +++ b/lib/MCE/Channel/MutexFast.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use base 'MCE::Channel'; use MCE::Mutex (); @@ -300,7 +300,7 @@ MCE::Channel::MutexFast - Fast channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::MutexFast version 1.896 +This document describes MCE::Channel::MutexFast version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/Simple.pm b/lib/MCE/Channel/Simple.pm index 5ca1893..b591d63 100644 --- a/lib/MCE/Channel/Simple.pm +++ b/lib/MCE/Channel/Simple.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use base 'MCE::Channel'; @@ -292,7 +292,7 @@ MCE::Channel::Simple - Channel tuned for one producer and one consumer =head1 VERSION -This document describes MCE::Channel::Simple version 1.896 +This document describes MCE::Channel::Simple version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/SimpleFast.pm b/lib/MCE/Channel/SimpleFast.pm index e20b3b2..2713931 100644 --- a/lib/MCE/Channel/SimpleFast.pm +++ b/lib/MCE/Channel/SimpleFast.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use base 'MCE::Channel'; @@ -300,7 +300,7 @@ MCE::Channel::SimpleFast - Fast channel tuned for one producer and one consumer =head1 VERSION -This document describes MCE::Channel::SimpleFast version 1.896 +This document describes MCE::Channel::SimpleFast version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/Threads.pm b/lib/MCE/Channel/Threads.pm index 6c2f528..39815eb 100644 --- a/lib/MCE/Channel/Threads.pm +++ b/lib/MCE/Channel/Threads.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use threads; use threads::shared; @@ -315,7 +315,7 @@ MCE::Channel::Threads - Channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::Threads version 1.896 +This document describes MCE::Channel::Threads version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/ThreadsFast.pm b/lib/MCE/Channel/ThreadsFast.pm index f2e5cb1..e59a3c0 100644 --- a/lib/MCE/Channel/ThreadsFast.pm +++ b/lib/MCE/Channel/ThreadsFast.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use threads; use threads::shared; @@ -321,7 +321,7 @@ MCE::Channel::ThreadsFast - Fast channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::ThreadsFast version 1.896 +This document describes MCE::Channel::ThreadsFast version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Child.pm b/lib/MCE/Child.pm index efb3349..721f793 100644 --- a/lib/MCE/Child.pm +++ b/lib/MCE/Child.pm @@ -11,7 +11,7 @@ no warnings qw( threads recursion uninitialized once redefine ); package MCE::Child; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitExplicitReturnUndef) @@ -80,6 +80,17 @@ sub _max_workers { bless my $_SELF = { MGR_ID => "$$.$_tid", WRK_ID => $$ }, __PACKAGE__; +sub MCE::Child::_guard::DESTROY { + my ($pkg, $id) = @{ $_[0] }; + + if (defined $pkg && $id eq "$$.$_tid") { + @{ $_[0] } = (); + MCE::Child->finish($pkg); + } + + return; +} + sub init { shift if ( defined $_[0] && $_[0] eq __PACKAGE__ ); @@ -137,7 +148,9 @@ sub init { require POSIX if ( $mngd->{on_finish} && !$INC{'POSIX.pm'} && !$_is_MSWin32 ); - return; + defined wantarray + ? bless([$pkg, "$$.$_tid"], MCE::Child::_guard::) + : (); } ############################################################################### @@ -345,7 +358,7 @@ sub finish { _croak('Usage: MCE::Child->finish()') if ref($_[0]); shift if ( defined $_[0] && $_[0] eq __PACKAGE__ ); - my $pkg = defined($_[0]) ? $_[0] : caller(); + my $pkg = defined($_[0]) ? shift : "$$.$_tid.".caller(); if ( $pkg eq 'MCE' ) { for my $key ( keys %{ $_LIST } ) { MCE::Child->finish($key); } @@ -1009,7 +1022,7 @@ MCE::Child - A threads-like parallelization module compatible with Perl 5.8 =head1 VERSION -This document describes MCE::Child version 1.896 +This document describes MCE::Child version 1.897 =head1 SYNOPSIS @@ -1295,7 +1308,10 @@ processes not yet joined. The init function accepts a list of MCE::Child options. - MCE::Child->init( +In scalar context (API available since 1.897), call Cfinish> +automatically upon leaving the scope or program. + + my $guard = MCE::Child->init( max_workers => 'auto', # default undef, unlimited # Specify a percentage. MCE::Child 1.876+. diff --git a/lib/MCE/Core.pod b/lib/MCE/Core.pod index 1e7e9e1..39f25cc 100644 --- a/lib/MCE/Core.pod +++ b/lib/MCE/Core.pod @@ -5,7 +5,7 @@ MCE::Core - Documentation describing the core MCE API =head1 VERSION -This document describes MCE::Core version 1.896 +This document describes MCE::Core version 1.897 =head1 SYNOPSIS diff --git a/lib/MCE/Core/Input/Generator.pm b/lib/MCE/Core/Input/Generator.pm index b7ac667..468f222 100644 --- a/lib/MCE/Core/Input/Generator.pm +++ b/lib/MCE/Core/Input/Generator.pm @@ -15,7 +15,7 @@ package MCE::Core::Input::Generator; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## Items below are folded into MCE. @@ -220,7 +220,7 @@ MCE::Core::Input::Generator - Sequence of numbers (for task_id > 0) =head1 VERSION -This document describes MCE::Core::Input::Generator version 1.896 +This document describes MCE::Core::Input::Generator version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Handle.pm b/lib/MCE/Core/Input/Handle.pm index f34a1b3..8261648 100644 --- a/lib/MCE/Core/Input/Handle.pm +++ b/lib/MCE/Core/Input/Handle.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Handle; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## Items below are folded into MCE. @@ -278,7 +278,7 @@ MCE::Core::Input::Handle - File path and Scalar reference input reader =head1 VERSION -This document describes MCE::Core::Input::Handle version 1.896 +This document describes MCE::Core::Input::Handle version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Iterator.pm b/lib/MCE/Core/Input/Iterator.pm index e529a48..adbfe90 100644 --- a/lib/MCE/Core/Input/Iterator.pm +++ b/lib/MCE/Core/Input/Iterator.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Iterator; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## Items below are folded into MCE. @@ -129,7 +129,7 @@ MCE::Core::Input::Iterator - Iterator reader =head1 VERSION -This document describes MCE::Core::Input::Iterator version 1.896 +This document describes MCE::Core::Input::Iterator version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Request.pm b/lib/MCE/Core/Input/Request.pm index eef5422..fe6bb9e 100644 --- a/lib/MCE/Core/Input/Request.pm +++ b/lib/MCE/Core/Input/Request.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Request; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## Items below are folded into MCE. @@ -200,7 +200,7 @@ MCE::Core::Input::Request - Array reference and Glob reference input reader =head1 VERSION -This document describes MCE::Core::Input::Request version 1.896 +This document describes MCE::Core::Input::Request version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Sequence.pm b/lib/MCE/Core/Input/Sequence.pm index 2f6ee3e..852d71f 100644 --- a/lib/MCE/Core/Input/Sequence.pm +++ b/lib/MCE/Core/Input/Sequence.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Sequence; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## Items below are folded into MCE. @@ -229,7 +229,7 @@ MCE::Core::Input::Sequence - Sequence of numbers (for task_id == 0) =head1 VERSION -This document describes MCE::Core::Input::Sequence version 1.896 +This document describes MCE::Core::Input::Sequence version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Manager.pm b/lib/MCE/Core/Manager.pm index afca1ab..8b3bbe3 100644 --- a/lib/MCE/Core/Manager.pm +++ b/lib/MCE/Core/Manager.pm @@ -14,7 +14,7 @@ package MCE::Core::Manager; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -1041,7 +1041,7 @@ MCE::Core::Manager - Core methods for the manager process =head1 VERSION -This document describes MCE::Core::Manager version 1.896 +This document describes MCE::Core::Manager version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Validation.pm b/lib/MCE/Core/Validation.pm index 35e931b..8a71aad 100644 --- a/lib/MCE/Core/Validation.pm +++ b/lib/MCE/Core/Validation.pm @@ -14,7 +14,7 @@ package MCE::Core::Validation; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## Items below are folded into MCE. @@ -402,7 +402,7 @@ MCE::Core::Validation - Core validation methods for Many-Core Engine =head1 VERSION -This document describes MCE::Core::Validation version 1.896 +This document describes MCE::Core::Validation version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Worker.pm b/lib/MCE/Core/Worker.pm index 18682b2..bf619ed 100644 --- a/lib/MCE/Core/Worker.pm +++ b/lib/MCE/Core/Worker.pm @@ -14,7 +14,7 @@ package MCE::Core::Worker; use strict; use warnings; -our $VERSION = '1.896'; +our $VERSION = '1.897'; my $_tid = $INC{'threads.pm'} ? threads->tid() : 0; @@ -738,7 +738,7 @@ MCE::Core::Worker - Core methods for the worker process =head1 VERSION -This document describes MCE::Core::Worker version 1.896 +This document describes MCE::Core::Worker version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Examples.pod b/lib/MCE/Examples.pod index e6bef6b..c537ab1 100644 --- a/lib/MCE/Examples.pod +++ b/lib/MCE/Examples.pod @@ -5,7 +5,7 @@ MCE::Examples - Various examples and demonstrations =head1 VERSION -This document describes MCE::Examples version 1.896 +This document describes MCE::Examples version 1.897 =head1 INCLUDED WITH THE DISTRIBUTION diff --git a/lib/MCE/Flow.pm b/lib/MCE/Flow.pm index 6258327..8cb2a74 100644 --- a/lib/MCE/Flow.pm +++ b/lib/MCE/Flow.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -94,6 +94,17 @@ sub import { ## ############################################################################### +sub MCE::Flow::_guard::DESTROY { + my ($_pkg, $_id) = @{ $_[0] }; + + if (defined $_pkg && $_id eq "$$.$_tid") { + @{ $_[0] } = (); + MCE::Flow->finish($_pkg); + } + + return; +} + sub init (@) { shift if (defined $_[0] && $_[0] eq 'MCE::Flow'); @@ -103,7 +114,9 @@ sub init (@) { @_ = (); - return; + defined wantarray + ? bless([$_pkg, "$$.$_tid"], MCE::Flow::_guard::) + : (); } sub finish (@) { @@ -482,7 +495,7 @@ MCE::Flow - Parallel flow model for building creative applications =head1 VERSION -This document describes MCE::Flow version 1.896 +This document describes MCE::Flow version 1.897 =head1 DESCRIPTION @@ -811,12 +824,14 @@ Specify C<< Sereal => 0 >> to use Storable instead. =back The init function accepts a hash of MCE options. Unlike with MCE::Stream, -both gather and bounds_only options may be specified when calling init -(not shown below). +both gather and bounds_only options may be specified (not shown below). + +In scalar context (API available since 1.897), call Cfinish> +automatically upon leaving the scope or program. use MCE::Flow; - MCE::Flow->init( + my $guard = MCE::Flow->init( chunk_size => 1, max_workers => 4, user_begin => sub { diff --git a/lib/MCE/Grep.pm b/lib/MCE/Grep.pm index bdb38d6..8eade5a 100644 --- a/lib/MCE/Grep.pm +++ b/lib/MCE/Grep.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -110,6 +110,17 @@ sub _gather { ## ############################################################################### +sub MCE::Grep::_guard::DESTROY { + my ($_pkg, $_id) = @{ $_[0] }; + + if (defined $_pkg && $_id eq "$$.$_tid") { + @{ $_[0] } = (); + MCE::Grep->finish($_pkg); + } + + return; +} + sub init (@) { shift if (defined $_[0] && $_[0] eq 'MCE::Grep'); @@ -122,7 +133,9 @@ sub init (@) { @_ = (); - return; + defined wantarray + ? bless([$_pkg, "$$.$_tid"], MCE::Grep::_guard::) + : (); } sub finish (@) { @@ -453,7 +466,7 @@ MCE::Grep - Parallel grep model similar to the native grep function =head1 VERSION -This document describes MCE::Grep version 1.896 +This document describes MCE::Grep version 1.897 =head1 SYNOPSIS @@ -637,9 +650,12 @@ Specify C<< Sereal => 0 >> to use Storable instead. The init function accepts a hash of MCE options. The gather option, if specified, is ignored due to being used internally by the module. +In scalar context (API available since 1.897), call Cfinish> +automatically upon leaving the scope or program. + use MCE::Grep; - MCE::Grep->init( + my $guard = MCE::Grep->init( chunk_size => 1, max_workers => 4, user_begin => sub { diff --git a/lib/MCE/Loop.pm b/lib/MCE/Loop.pm index 41cec4f..389c250 100644 --- a/lib/MCE/Loop.pm +++ b/lib/MCE/Loop.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -92,6 +92,17 @@ sub import { ## ############################################################################### +sub MCE::Loop::_guard::DESTROY { + my ($_pkg, $_id) = @{ $_[0] }; + + if (defined $_pkg && $_id eq "$$.$_tid") { + @{ $_[0] } = (); + MCE::Loop->finish($_pkg); + } + + return; +} + sub init (@) { shift if (defined $_[0] && $_[0] eq 'MCE::Loop'); @@ -101,7 +112,9 @@ sub init (@) { @_ = (); - return; + defined wantarray + ? bless([$_pkg, "$$.$_tid"], MCE::Loop::_guard::) + : (); } sub finish (@) { @@ -364,7 +377,7 @@ MCE::Loop - MCE model for building parallel loops =head1 VERSION -This document describes MCE::Loop version 1.896 +This document describes MCE::Loop version 1.897 =head1 DESCRIPTION @@ -552,9 +565,12 @@ Specify C<< Sereal => 0 >> to use Storable instead. The init function accepts a hash of MCE options. +In scalar context (API available since 1.897), call Cfinish> +automatically upon leaving the scope or program. + use MCE::Loop; - MCE::Loop->init( + my $guard = MCE::Loop->init( chunk_size => 1, max_workers => 4, user_begin => sub { diff --git a/lib/MCE/Map.pm b/lib/MCE/Map.pm index beec70b..7ed518e 100644 --- a/lib/MCE/Map.pm +++ b/lib/MCE/Map.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -110,6 +110,17 @@ sub _gather { ## ############################################################################### +sub MCE::Map::_guard::DESTROY { + my ($_pkg, $_id) = @{ $_[0] }; + + if (defined $_pkg && $_id eq "$$.$_tid") { + @{ $_[0] } = (); + MCE::Map->finish($_pkg); + } + + return; +} + sub init (@) { shift if (defined $_[0] && $_[0] eq 'MCE::Map'); @@ -122,7 +133,9 @@ sub init (@) { @_ = (); - return; + defined wantarray + ? bless([$_pkg, "$$.$_tid"], MCE::Map::_guard::) + : (); } sub finish (@) { @@ -453,7 +466,7 @@ MCE::Map - Parallel map model similar to the native map function =head1 VERSION -This document describes MCE::Map version 1.896 +This document describes MCE::Map version 1.897 =head1 SYNOPSIS @@ -572,9 +585,12 @@ Specify C<< Sereal => 0 >> to use Storable instead. The init function accepts a hash of MCE options. The gather option, if specified, is ignored due to being used internally by the module. +In scalar context (API available since 1.897), call Cfinish> +automatically upon leaving the scope or program. + use MCE::Map; - MCE::Map->init( + my $guard = MCE::Map->init( chunk_size => 1, max_workers => 4, user_begin => sub { diff --git a/lib/MCE/Mutex.pm b/lib/MCE/Mutex.pm index f5d42e8..a968dd6 100644 --- a/lib/MCE/Mutex.pm +++ b/lib/MCE/Mutex.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -64,7 +64,7 @@ MCE::Mutex - Locking for Many-Core Engine =head1 VERSION -This document describes MCE::Mutex version 1.896 +This document describes MCE::Mutex version 1.897 =head1 SYNOPSIS diff --git a/lib/MCE/Mutex/Channel.pm b/lib/MCE/Mutex/Channel.pm index a704610..8d163ae 100644 --- a/lib/MCE/Mutex/Channel.pm +++ b/lib/MCE/Mutex/Channel.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use if $^O eq 'MSWin32', 'threads'; use if $^O eq 'MSWin32', 'threads::shared'; @@ -187,7 +187,7 @@ MCE::Mutex::Channel - Mutex locking via a pipe or socket =head1 VERSION -This document describes MCE::Mutex::Channel version 1.896 +This document describes MCE::Mutex::Channel version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Mutex/Channel2.pm b/lib/MCE/Mutex/Channel2.pm index 53edb6d..5effafb 100644 --- a/lib/MCE/Mutex/Channel2.pm +++ b/lib/MCE/Mutex/Channel2.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use if $^O eq 'MSWin32', 'threads'; use if $^O eq 'MSWin32', 'threads::shared'; @@ -154,7 +154,7 @@ MCE::Mutex::Channel2 - Provides two mutexes using a single channel =head1 VERSION -This document describes MCE::Mutex::Channel2 version 1.896 +This document describes MCE::Mutex::Channel2 version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Mutex/Flock.pm b/lib/MCE/Mutex/Flock.pm index 4206882..f9ce23e 100644 --- a/lib/MCE/Mutex/Flock.pm +++ b/lib/MCE/Mutex/Flock.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; use base 'MCE::Mutex'; use Fcntl ':flock'; @@ -211,7 +211,7 @@ MCE::Mutex::Flock - Mutex locking via Fcntl =head1 VERSION -This document describes MCE::Mutex::Flock version 1.896 +This document describes MCE::Mutex::Flock version 1.897 =head1 DESCRIPTION diff --git a/lib/MCE/Queue.pm b/lib/MCE/Queue.pm index dd7eb68..2ce1eb4 100644 --- a/lib/MCE/Queue.pm +++ b/lib/MCE/Queue.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (Subroutines::ProhibitExplicitReturnUndef) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -1506,7 +1506,7 @@ MCE::Queue - Hybrid (normal and priority) queues =head1 VERSION -This document describes MCE::Queue version 1.896 +This document describes MCE::Queue version 1.897 =head1 SYNOPSIS diff --git a/lib/MCE/Relay.pm b/lib/MCE/Relay.pm index 86c0059..9611248 100644 --- a/lib/MCE/Relay.pm +++ b/lib/MCE/Relay.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized numeric ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -368,7 +368,7 @@ MCE::Relay - Extends Many-Core Engine with relay capabilities =head1 VERSION -This document describes MCE::Relay version 1.896 +This document describes MCE::Relay version 1.897 =head1 SYNOPSIS diff --git a/lib/MCE/Signal.pm b/lib/MCE/Signal.pm index 0e39747..966b577 100644 --- a/lib/MCE/Signal.pm +++ b/lib/MCE/Signal.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) @@ -445,7 +445,7 @@ MCE::Signal - Temporary directory creation/cleanup and signal handling =head1 VERSION -This document describes MCE::Signal version 1.896 +This document describes MCE::Signal version 1.897 =head1 SYNOPSIS diff --git a/lib/MCE/Step.pm b/lib/MCE/Step.pm index e3e0a72..914b9d2 100644 --- a/lib/MCE/Step.pm +++ b/lib/MCE/Step.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -248,6 +248,17 @@ sub _task_end { ## ############################################################################### +sub MCE::Step::_guard::DESTROY { + my ($_pkg, $_id) = @{ $_[0] }; + + if (defined $_pkg && $_id eq "$$.$_tid") { + @{ $_[0] } = (); + MCE::Step->finish($_pkg); + } + + return; +} + sub init (@) { shift if (defined $_[0] && $_[0] eq 'MCE::Step'); @@ -257,7 +268,9 @@ sub init (@) { @_ = (); - return; + defined wantarray + ? bless([$_pkg, "$$.$_tid"], MCE::Step::_guard::) + : (); } sub finish (@) { @@ -700,7 +713,7 @@ MCE::Step - Parallel step model for building creative steps =head1 VERSION -This document describes MCE::Step version 1.896 +This document describes MCE::Step version 1.897 =head1 DESCRIPTION @@ -982,12 +995,14 @@ Specify C<< Sereal => 0 >> to use Storable instead. =back The init function accepts a hash of MCE options. Unlike with MCE::Stream, -both gather and bounds_only options may be specified when calling init -(not shown below). +both gather and bounds_only options may be specified (not shown below). + +In scalar context (API available since 1.897), call Cfinish> +automatically upon leaving the scope or program. use MCE::Step; - MCE::Step->init( + my $guard = MCE::Step->init( chunk_size => 1, max_workers => 4, user_begin => sub { diff --git a/lib/MCE/Stream.pm b/lib/MCE/Stream.pm index fd2c104..fc62363 100644 --- a/lib/MCE/Stream.pm +++ b/lib/MCE/Stream.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -147,6 +147,17 @@ sub _task_end { ## ############################################################################### +sub MCE::Stream::_guard::DESTROY { + my ($_pkg, $_id) = @{ $_[0] }; + + if (defined $_pkg && $_id eq "$$.$_tid") { + @{ $_[0] } = (); + MCE::Stream->finish($_pkg); + } + + return; +} + sub init (@) { shift if (defined $_[0] && $_[0] eq 'MCE::Stream'); @@ -159,7 +170,9 @@ sub init (@) { @_ = (); - return; + defined wantarray + ? bless([$_pkg, "$$.$_tid"], MCE::Stream::_guard::) + : (); } sub finish (@) { @@ -678,7 +691,7 @@ MCE::Stream - Parallel stream model for chaining multiple maps and greps =head1 VERSION -This document describes MCE::Stream version 1.896 +This document describes MCE::Stream version 1.897 =head1 SYNOPSIS @@ -813,9 +826,12 @@ The init function accepts a hash of MCE options. The gather and bounds_only options, if specified, are ignored due to being used internally by the module (not shown below). +In scalar context (API available since 1.897), call Cfinish> +automatically upon leaving the scope or program. + use MCE::Stream; - MCE::Stream->init( + my $guard = MCE::Stream->init( chunk_size => 1, max_workers => 4, user_begin => sub { diff --git a/lib/MCE/Subs.pm b/lib/MCE/Subs.pm index f91e42e..64814e8 100644 --- a/lib/MCE/Subs.pm +++ b/lib/MCE/Subs.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (Subroutines::ProhibitSubroutinePrototypes) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -206,7 +206,7 @@ MCE::Subs - Exports functions mapped directly to MCE methods =head1 VERSION -This document describes MCE::Subs version 1.896 +This document describes MCE::Subs version 1.897 =head1 SYNOPSIS diff --git a/lib/MCE/Util.pm b/lib/MCE/Util.pm index d81f4d2..289a8dd 100644 --- a/lib/MCE/Util.pm +++ b/lib/MCE/Util.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized numeric ); -our $VERSION = '1.896'; +our $VERSION = '1.897'; ## no critic (BuiltinFunctions::ProhibitStringyEval) @@ -435,7 +435,7 @@ MCE::Util - Utility functions =head1 VERSION -This document describes MCE::Util version 1.896 +This document describes MCE::Util version 1.897 =head1 SYNOPSIS diff --git a/t/06_candy.t b/t/06_candy.t new file mode 100644 index 0000000..d40450f --- /dev/null +++ b/t/06_candy.t @@ -0,0 +1,51 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Test::More; + +BEGIN { + use_ok 'MCE'; + use_ok 'MCE::Flow'; + use_ok 'MCE::Candy'; +} + +{ + my @data; + + MCE->new( + max_workers => 4, + input_data => [ 1 .. 4 ], + gather => MCE::Candy::out_iter_array(\@data), + user_func => sub { + my ($mce, $chunk_ref, $chunk_id) = @_; + MCE->gather( $chunk_id, $chunk_ref->[0] * 2 ); + } + )->run; + + is( join('', @data), '2468', 'check out_iter_array' ); +} + +{ + my @data; + + sub append_data { + push @data, $_[0]; + } + + mce_flow { + max_workers => 4, + gather => MCE::Candy::out_iter_callback(\&append_data) + }, + sub { + MCE->gather( MCE->wid, MCE->wid * 2 ); + }; + + MCE::Flow->finish; + + is( join('', @data), '2468', 'check out_iter_callback' ); +} + +done_testing; +