use Scalar::Util qw(reftype refaddr blessed);
-our $VERSION = '1.29';
+our $VERSION = '1.31';
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
=head1 VERSION
-This document describes threads::shared version 1.29
+This document describes threads::shared version 1.31
=head1 SYNOPSIS
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/>
#
#####
{
- 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;
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++;
}
}
}
+
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;
}