From 5b48f78c51c77f1ce79e9b542433a4daa2433457 Mon Sep 17 00:00:00 2001 From: "Jerry D. Hedden" Date: Mon, 10 Aug 2009 15:26:25 -0400 Subject: [PATCH] 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 Date: Mon, 10 Aug 2009 15:22:54 -0400 Subject: [PATCH] Upgrade to threads::shared 1.31 Signed-off-by: H.Merijn Brand --- 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 Discussion Forum on CPAN: L Annotated POD for L: -L +L Source repository: L 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; } -- 2.7.4