1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
From: Niko Tyni <ntyni@debian.org>
Subject: make the threads-shared test suite more robust, fixing failures on hppa
Closes: 554218
Fix from threads-shared-1.31:
Handle thread creation failures in tests due to lack of memory, etc.
---
ext/threads-shared/t/stress.t | 28 ++++++++++++++++++++++++----
1 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/ext/threads-shared/t/stress.t b/ext/threads-shared/t/stress.t
index e36ab0a..adfd1ed 100755
--- a/ext/threads-shared/t/stress.t
+++ b/ext/threads-shared/t/stress.t
@@ -39,7 +39,11 @@ use threads::shared;
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;
}
--
tg: (daf8b46..) fixes/hppa-thread-eagain (depends on: upstream)
|