In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/5b48f78c51c77f1ce79e9b542433a4daa2433457?hp=66ce101fb6dbfa9fd673b3838fd1e2d14f3f9874>

- Log -----------------------------------------------------------------
commit 5b48f78c51c77f1ce79e9b542433a4daa2433457
Author: Jerry D. Hedden <[email protected]>
Date:   Mon Aug 10 15:26:25 2009 -0400

    Upgrade to threads::shared 1.31
    
    Attached patch changes t/stress.t such that it more robustly handles
    thread creation failures due to 'no more processes', 'out of memory',
    etc..  Such failures are not indicative of problems with the
    'threads::shared' module.
    
    From 2440c97ff633f0a33bf1ca0cceecfd4448cd6167 Mon Sep 17 00:00:00 2001
    From: Jerry D. Hedden <[email protected]>
    Date: Mon, 10 Aug 2009 15:22:54 -0400
    Subject: [PATCH] Upgrade to threads::shared 1.31
    
    Signed-off-by: H.Merijn Brand <[email protected]>
-----------------------------------------------------------------------

Summary of changes:
 ext/threads-shared/shared.pm  |    6 +++---
 ext/threads-shared/t/stress.t |   30 +++++++++++++++++++++++++-----
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/ext/threads-shared/shared.pm b/ext/threads-shared/shared.pm
index 722e3ce..b1b4552 100644
--- a/ext/threads-shared/shared.pm
+++ b/ext/threads-shared/shared.pm
@@ -7,7 +7,7 @@ use warnings;
 
 use Scalar::Util qw(reftype refaddr blessed);
 
-our $VERSION = '1.29';
+our $VERSION = '1.31';
 my $XS_VERSION = $VERSION;
 $VERSION = eval $VERSION;
 
@@ -187,7 +187,7 @@ threads::shared - Perl extension for sharing data 
structures between threads
 
 =head1 VERSION
 
-This document describes threads::shared version 1.29
+This document describes threads::shared version 1.31
 
 =head1 SYNOPSIS
 
@@ -588,7 +588,7 @@ L<threads::shared> Discussion Forum on CPAN:
 L<http://www.cpanforum.com/dist/threads-shared>
 
 Annotated POD for L<threads::shared>:
-L<http://annocpan.org/~JDHEDDEN/threads-shared-1.29/shared.pm>
+L<http://annocpan.org/~JDHEDDEN/threads-shared-1.31/shared.pm>
 
 Source repository:
 L<http://code.google.com/p/threads-shared/>
diff --git a/ext/threads-shared/t/stress.t b/ext/threads-shared/t/stress.t
index e36ab0a..6648867 100644
--- a/ext/threads-shared/t/stress.t
+++ b/ext/threads-shared/t/stress.t
@@ -32,14 +32,18 @@ use threads::shared;
 #
 #####
 {
-    my $cnt = 50;
+    my $cnt = 200;
 
     my $TIMEOUT = 60;
 
     my $mutex = 1;
     share($mutex);
 
+    my $warning;
+    $SIG{__WARN__} = sub { $warning = shift; };
+
     my @threads;
+
     for (reverse(1..$cnt)) {
         $threads[$_] = threads->create(sub {
                             my $tnum = shift;
@@ -71,10 +75,26 @@ use threads::shared;
                             cond_broadcast($mutex);
                             return ('okay');
                       }, $_);
+
+        # Handle thread creation failures
+        if ($warning) {
+            my $printit = 1;
+            if ($warning =~ /returned 11/) {
+                $warning = "Thread creation failed due to 'No more 
processes'\n";
+                $printit = (! $ENV{'PERL_CORE'});
+            } elsif ($warning =~ /returned 12/) {
+                $warning = "Thread creation failed due to 'No more memory'\n";
+                $printit = (! $ENV{'PERL_CORE'});
+            }
+            print(STDERR "# Warning: $warning") if ($printit);
+            lock($mutex);
+            $mutex = $_ + 1;
+            last;
+        }
     }
 
     # Gather thread results
-    my ($okay, $failures, $timeouts, $unknown) = (0, 0, 0, 0);
+    my ($okay, $failures, $timeouts, $unknown) = (0, 0, 0, 0, 0);
     for (1..$cnt) {
         if (! $threads[$_]) {
             $failures++;
@@ -92,10 +112,10 @@ use threads::shared;
             }
         }
     }
+
     if ($failures) {
-        # Most likely due to running out of memory
-        print(STDERR "# Warning: $failures threads failed\n");
-        print(STDERR "# Note: errno 12 = ENOMEM\n");
+        my $only = $cnt - $failures;
+        print(STDERR "# Warning: Intended to use $cnt threads, but could only 
muster $only\n");
         $cnt -= $failures;
     }
 

--
Perl5 Master Repository

Reply via email to