6 if (! $Config{'useithreads'}) {
7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
10 if ($^O eq 'hpux' && $Config{osvers} <= 10.20) {
11 print("1..0 # SKIP Broken under HP-UX 10.20\n");
16 use ExtUtils::testlib;
20 print("1..1\n"); ### Number of tests that will be run ###
26 ### Start of Testing ###
30 # Launches a bunch of threads which are then
31 # restricted to finishing in numerical order
43 $SIG{__WARN__} = sub { $warning = shift; };
47 for (reverse(1..$cnt)) {
48 $threads[$_] = threads->create(sub {
50 my $timeout = time() + $TIMEOUT;
53 # Randomize the amount of work the thread does
55 for (0..(500000+int(rand(500000)))) {
62 # Wait for my turn to finish
63 while ($mutex != $tnum) {
64 if (! cond_timedwait($mutex, $timeout)) {
65 if ($mutex == $tnum) {
66 return ('timed out - cond_broadcast not received');
75 cond_broadcast($mutex);
79 # Handle thread creation failures
82 if ($warning =~ /returned 11/) {
83 $warning = "Thread creation failed due to 'No more processes'\n";
84 $printit = (! $ENV{'PERL_CORE'});
85 } elsif ($warning =~ /returned 12/) {
86 $warning = "Thread creation failed due to 'No more memory'\n";
87 $printit = (! $ENV{'PERL_CORE'});
89 print(STDERR "# Warning: $warning") if ($printit);
96 # Gather thread results
97 my ($okay, $failures, $timeouts, $unknown) = (0, 0, 0, 0, 0);
102 my $rc = $threads[$_]->join();
105 } elsif ($rc =~ /^timed out/) {
107 } elsif ($rc eq 'okay') {
111 print(STDERR "# Unknown error: $rc\n");
117 my $only = $cnt - $failures;
118 print(STDERR "# Warning: Intended to use $cnt threads, but could only muster $only\n");
122 if ($unknown || (($okay + $timeouts) != $cnt)) {
124 my $too_few = $cnt - ($okay + $timeouts + $unknown);
125 print(STDERR "# Test failed:\n");
126 print(STDERR "#\t$too_few too few threads reported\n") if $too_few;
127 print(STDERR "#\t$unknown unknown errors\n") if $unknown;
128 print(STDERR "#\t$timeouts threads timed out\n") if $timeouts;
130 } elsif ($timeouts) {
131 # Frequently fails under MSWin32 due to deadlocking bug in Windows
132 # hence test is TODO under MSWin32
133 # http://rt.perl.org/rt3/Public/Bug/Display.html?id=41574
134 # http://support.microsoft.com/kb/175332
135 if ($^O eq 'MSWin32') {
136 print("not ok 1 # TODO - not reliable under MSWin32\n")
139 print(STDERR "# Test failed: $timeouts threads timed out\n");