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 for (reverse(1..$cnt)) {
44 $threads[$_] = threads->create(sub {
46 my $timeout = time() + $TIMEOUT;
49 # Randomize the amount of work the thread does
51 for (0..(500000+int(rand(500000)))) {
58 # Wait for my turn to finish
59 while ($mutex != $tnum) {
60 if (! cond_timedwait($mutex, $timeout)) {
61 if ($mutex == $tnum) {
62 return ('timed out - cond_broadcast not received');
71 cond_broadcast($mutex);
76 # Gather thread results
77 my ($okay, $failures, $timeouts, $unknown) = (0, 0, 0, 0);
82 my $rc = $threads[$_]->join();
85 } elsif ($rc =~ /^timed out/) {
87 } elsif ($rc eq 'okay') {
91 print(STDERR "# Unknown error: $rc\n");
96 # Most likely due to running out of memory
97 print(STDERR "# Warning: $failures threads failed\n");
98 print(STDERR "# Note: errno 12 = ENOMEM\n");
102 if ($unknown || (($okay + $timeouts) != $cnt)) {
104 my $too_few = $cnt - ($okay + $timeouts + $unknown);
105 print(STDERR "# Test failed:\n");
106 print(STDERR "#\t$too_few too few threads reported\n") if $too_few;
107 print(STDERR "#\t$unknown unknown errors\n") if $unknown;
108 print(STDERR "#\t$timeouts threads timed out\n") if $timeouts;
110 } elsif ($timeouts) {
111 # Frequently fails under MSWin32 due to deadlocking bug in Windows
112 # hence test is TODO under MSWin32
113 # http://rt.perl.org/rt3/Public/Bug/Display.html?id=41574
114 # http://support.microsoft.com/kb/175332
115 if ($^O eq 'MSWin32') {
116 print("not ok 1 # TODO - not reliable under MSWin32\n")
119 print(STDERR "# Test failed: $timeouts threads timed out\n");