MCE

 view release on metacpan or  search on metacpan

lib/MCE.pm  view on Meta::CPAN

      eval 'use threads; use threads::shared;';
   }
   elsif ( $INC{'threads.pm'} && ! $INC{'threads/shared.pm'} ) {
      eval 'use threads::shared;';
   }

   $_has_threads = $INC{'threads.pm'} ? 1 : 0;
   $_tid = $_has_threads ? threads->tid() : 0;
   $_oid = "$$.$_tid";

   if ( $] ge '5.008008' && ! $INC{'PDL.pm'} ) {
      eval 'use Sereal::Encoder 3.015; use Sereal::Decoder 3.015;';
      if ( ! $@ ) {
         my $_encoder_ver = int( Sereal::Encoder->VERSION() );
         my $_decoder_ver = int( Sereal::Decoder->VERSION() );
         if ( $_encoder_ver - $_decoder_ver == 0 ) {
            $_freeze = \&Sereal::Encoder::encode_sereal;
            $_thaw   = \&Sereal::Decoder::decode_sereal;
         }
      }
   }

lib/MCE.pm  view on Meta::CPAN

   # Math::Random, Math::Random::MT::Auto, and PDL.
   #
   # MCE 1.892, 2024-06-08: Enable predictability running threads.
   # Output matches non-threads for CORE, Math::Prime::Util, and
   # Math::Random::MT::Auto. https://perlmonks.org/?node_id=11159834

   {
      my $_wid  = $_args[1];
      my $_seed = abs($self->{_seed} - ($_wid * 100000)) % 2147483560;

      CORE::srand($_seed) if (!$self->{use_threads} || $] ge '5.020000'); # drand48
      Math::Prime::Util::srand($_seed) if $INC{'Math/Prime/Util.pm'};

      # [etj] identified a race condition in PDL running threads
      # https://perlmonks.org/?node_id=11159841
      if (!$self->{use_threads}) {
         PDL::srand($_seed) if $INC{'PDL.pm'} && PDL->can('srand'); # PDL 2.062 ~ 2.089
         PDL::srandom($_seed) if $INC{'PDL.pm'} && PDL->can('srandom'); # PDL 2.089_01+
      }
   }

lib/MCE/Channel.pm  view on Meta::CPAN

use if $^O eq 'MSWin32', 'threads';
use if $^O eq 'MSWin32', 'threads::shared';

use Carp ();

$Carp::Internal{ (__PACKAGE__) }++;

my ( $freeze, $thaw );

BEGIN {
   if ( $] ge '5.008008' && ! $INC{'PDL.pm'} ) {
      local $@;
      eval 'use Sereal::Encoder 3.015; use Sereal::Decoder 3.015;';
      if ( ! $@ ) {
         my $encoder_ver = int( Sereal::Encoder->VERSION() );
         my $decoder_ver = int( Sereal::Decoder->VERSION() );
         if ( $encoder_ver - $decoder_ver == 0 ) {
            $freeze = \&Sereal::Encoder::encode_sereal;
            $thaw   = \&Sereal::Decoder::decode_sereal;
         }
      }

lib/MCE/Child.pm  view on Meta::CPAN


   # ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~

   $MCE::_GMUTEX->lock() if ( $_tid && $MCE::_GMUTEX );

   my @args = @_; @_ = ();  # To avoid (Scalars leaked: N) messages
   my ( $killed, $pid );

   {
      local $SIG{TERM} = local $SIG{INT} = sub { $killed = $_[0] }
         if ( !$_is_MSWin32 && $] ge '5.010001' );

      local $SIG{TTIN}, local $SIG{TTOU}, local $SIG{WINCH}
         if ( !$_is_MSWin32 );

      $pid = fork();

      if ( !defined $pid ) {                                # error
         local $\; print {*STDERR} "fork error: $!\n";
      }
      elsif ( $pid ) {                                      # parent

lib/MCE/Mutex/Channel.pm  view on Meta::CPAN


use if $^O eq 'MSWin32', 'threads';
use if $^O eq 'MSWin32', 'threads::shared';

use base 'MCE::Mutex';
use MCE::Util ();
use Scalar::Util qw(looks_like_number weaken);
use Time::HiRes 'alarm';

my $is_MSWin32 = ($^O eq 'MSWin32') ? 1 : 0;
my $use_pipe = ($^O !~ /mswin|mingw|msys|cygwin/i && $] gt '5.010000');
my $tid = $INC{'threads.pm'} ? threads->tid : 0;

sub CLONE {
    $tid = threads->tid if $INC{'threads.pm'};
}

sub MCE::Mutex::Channel::_guard::DESTROY {
    my ($pid, $obj) = @{ $_[0] };
    CORE::syswrite($obj->{_w_sock}, '0'), $obj->{ $pid } = 0 if $obj->{ $pid };

lib/MCE/Signal.pm  view on Meta::CPAN

         }

         ## Remove temp directory.
         _remove_tmpdir() if defined($tmp_dir);

         ## Signal process group to die.
         if ($_is_sig == 1) {
            if ($_sig_name eq 'INT' && -t STDIN) { ## no critic
               print {*STDERR} "\n";
            }
            if ($INC{'threads.pm'} && ($] lt '5.012000' || threads->tid())) {
               ($_no_kill9 == 1 || $_sig_name eq 'PIPE')
                  ? CORE::kill('INT', $_is_MSWin32 ? -$$ : -getpgrp)
                  : CORE::kill('KILL', -$$);
            }
            else {
               CORE::kill('INT', $_is_MSWin32 ? -$$ : -getpgrp);
            }
         }
      }
   }

t/04_channel_threads.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use open qw(:std :utf8);

use Test::More;

BEGIN {
   plan skip_all => "Not used on Cygwin" if ( $^O eq 'cygwin' );

   if ( $] lt '5.010001' && $^O ne 'MSWin32' ) {
      plan skip_all => "old Perl and threads not supported on Unix platforms";
   }
   eval 'use threads'; ## no critic
   plan skip_all => "threads not available" if $@;

   use_ok 'MCE::Channel';
   use_ok 'MCE::Channel::Threads';
}

## https://sacred-texts.com/cla/usappho/sph02.htm (V)

t/04_channel_threads_mp.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use open qw(:std :utf8);

use Test::More;

BEGIN {
   plan skip_all => "Not used on Cygwin" if ( $^O eq 'cygwin' );

   if ( $] lt '5.010001' && $^O ne 'MSWin32' ) {
      plan skip_all => "old Perl and threads not supported on Unix platforms";
   }
   eval 'use threads'; ## no critic
   plan skip_all => "threads not available" if $@;

   use_ok 'MCE::Channel';
   use_ok 'MCE::Channel::Threads';
}

## https://sacred-texts.com/cla/usappho/sph02.htm (IV)

t/04_channel_threadsfast.t  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;

BEGIN {
   plan skip_all => "Not used on Cygwin" if ( $^O eq 'cygwin' );

   if ( $] lt '5.010001' && $^O ne 'MSWin32' ) {
      plan skip_all => "old Perl and threads not supported on Unix platforms";
   }
   eval 'use threads'; ## no critic
   plan skip_all => "threads not available" if $@;

   use_ok 'MCE::Channel';
   use_ok 'MCE::Channel::ThreadsFast';
}

my $chnl = MCE::Channel->new( impl => 'ThreadsFast' );

t/04_channel_threadsfast_mp.t  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;

BEGIN {
   plan skip_all => "Not used on Cygwin" if ( $^O eq 'cygwin' );

   if ( $] lt '5.010001' && $^O ne 'MSWin32' ) {
      plan skip_all => "old Perl and threads not supported on Unix platforms";
   }
   eval 'use threads'; ## no critic
   plan skip_all => "threads not available" if $@;

   use_ok 'MCE::Channel';
   use_ok 'MCE::Channel::ThreadsFast';
}

my $chnl = MCE::Channel->new( impl => 'ThreadsFast', mp => 1 );



( run in 0.435 second using v1.01-cache-2.11-cpan-cc502c75498 )