5 if ($ENV{'PERL_CORE'}){
7 unshift @INC, '../lib';
10 if (! $Config{'useithreads'}) {
11 print("1..0 # Skip: Perl not compiled with 'useithreads'\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
44 $threads[$_] = threads->create(sub {
46 my $timeout = time() + $TIMEOUT;
48 # Randomize the amount of work the thread does
50 for (0..(500000+int(rand(500000)))) {
57 # Wait for my turn to finish
58 while ($mutex != $tnum) {
59 if (! cond_timedwait($mutex, $timeout)) {
60 if ($mutex == $tnum) {
61 return ('timed out - cond_broadcast not received');
70 cond_broadcast($mutex);
75 # Gather thread results
76 my ($okay, $failures, $timeouts, $unknown) = (0, 0, 0, 0);
78 my $rc = $threads[$_]->join();
81 } elsif ($rc =~ /^timed out/) {
83 } elsif ($rc eq 'okay') {
87 print("# Unknown error: $rc\n");
91 if ($failures || $unknown || (($okay + $timeouts) != $cnt)) {
93 my $too_few = $cnt - ($okay + $failures + $timeouts + $unknown);
94 print(" - $too_few too few threads reported") if $too_few;
95 print(" - $failures threads failed") if $failures;
96 print(" - $unknown unknown errors") if $unknown;
97 print(" - $timeouts threads timed out") if $timeouts;
100 } elsif ($timeouts) {
101 # Frequently fails under MSWin32 due to deadlocking bug in Windows
102 # hence test is TODO under MSWin32
103 # http://rt.perl.org/rt3/Public/Bug/Display.html?id=41574
104 # http://support.microsoft.com/kb/175332
106 print(' # TODO - not reliable under MSWin32') if ($^O eq 'MSWin32');
107 print(" - $timeouts threads timed out\n");
111 print(' # TODO - not reliable under MSWin32') if ($^O eq 'MSWin32');