package Iter::Output;
sub new {
my ( $class, $path ) = @_;
my ( $order_id, $fh, %hold ) = ( 1 );
# Note: Do not open the file handle here, during construction.
# The reason is that sharing will fail (cannot serialize $fh).
MCE::Shared->share(
bless [ $path, $fh, \$order_id, \%hold ], $class
);
}
sub send {
...
}
sub close {
...
}
####
package Iter::Input;
sub new {
my ( $class, $chunk_size, $iterations ) = @_;
my ( $chunk_id, $seq_a ) = ( 0, 1 );
MCE::Shared->share(
bless [ $iterations, $chunk_size, \$chunk_id, \$seq_a ], $class
);
}
sub recv {
...
}
####
use threads;
...
test_threads();
sub test_threads {
my $start = time;
my @thrs;
# must save threads to join later
push @thrs, threads->create('work') for (1..$num_workers);
# wait for threads to finish
$_->join for @thrs;
# close the shared file handle, flushes buffer
$iter_o->close();
printf STDERR "testa done in %0.02f seconds\n", time - $start;
}