Change 22127 by [EMAIL PROTECTED] on 2004/01/13 08:55:10

        Integrate:
        [ 22122]
        Subject: Re: 5.8.3-RC1, ext/threads/shared/t/wait still hanging
        From: Mike Pomraning <[EMAIL PROTECTED]>
        Message-ID: <[EMAIL PROTECTED]>
        Date: Mon, 12 Jan 2004 12:41:52 -0600 (CST)

Affected files ...

... //depot/maint-5.8/perl/ext/threads/shared/t/wait.t#3 integrate

Differences ...

==== //depot/maint-5.8/perl/ext/threads/shared/t/wait.t#3 (text) ====
Index: perl/ext/threads/shared/t/wait.t
--- perl/ext/threads/shared/t/wait.t#2~22116~   Sun Jan 11 15:55:36 2004
+++ perl/ext/threads/shared/t/wait.t    Tue Jan 13 00:55:10 2004
@@ -29,6 +29,48 @@
     print "${not}ok " . ($Base + $offset) . " - $text\n";
 }
 
+sub forko (&$$); # To prevent deadlock from underlying pthread_* bugs (as in
+                 # stock RH9 glibc/NPTL) or from our own errors, we run tests
+                 # in separately forked and alarmed processes.
+
+*forko = ($^O =~ /^dos|os2|mswin32|netware$/i)  # Not on DOSish platforms
+? sub (&$$) { my $code = shift; goto &$code; }
+: sub (&$$) {
+  my ($code, $expected, $patience) = @_;
+  my ($test_num, $pid);
+  local *CHLD;
+
+  my $bump = $expected;
+
+  $patience ||= 60;
+
+  unless (defined($pid = open(CHLD, "-|"))) {
+    die "fork: $!\n";
+  }
+  if (! $pid) {   # Child -- run the test
+    $patience ||= 60;
+    alarm $patience;
+    &$code;
+    exit;
+  }
+
+  while (<CHLD>) {
+    $expected--, $test_num=$1 if /^(?:not )?ok (\d+)/;
+    #print "#forko: ($expected, $1) $_";
+    print;
+  }
+
+  close(CHLD);
+
+  while ($expected--) {
+    $test_num++;
+    print "not ok $test_num - child status $?\n";
+  }
+
+  $Base += $bump;
+
+};
+
 # - TEST basics
 
 ok(1, defined &cond_wait, "cond_wait() present");
@@ -69,11 +111,13 @@
   }
 
   # - TEST cond_wait
-  foreach (@wait_how) {
-    $test = "cond_wait [$_]";
-    threads->create(\&cw)->join;
-    $Base += 6;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_wait [$_]";
+      threads->create(\&cw)->join;
+      $Base += 6;
+    }
+  }, [EMAIL PROTECTED], 90);
 
   sub cw {
     my $thr;
@@ -98,11 +142,13 @@
 
   # - TEST cond_timedwait success
 
-  foreach (@wait_how) {
-    $test = "cond_timedwait [$_]";
-    threads->create(\&ctw, 5)->join;
-    $Base += 6;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_timedwait [$_]";
+      threads->create(\&ctw, 5)->join;
+      $Base += 6;
+    }
+  }, [EMAIL PROTECTED], 90);
 
   sub ctw($) {
     my $to = shift;
@@ -129,17 +175,21 @@
 
   # - TEST cond_timedwait timeout
 
-  foreach (@wait_how) {
-    $test = "cond_timedwait pause, timeout [$_]";
-    threads->create(\&ctw_fail, 3)->join;
-    $Base += 2;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_timedwait pause, timeout [$_]";
+      threads->create(\&ctw_fail, 3)->join;
+      $Base += 2;
+    }
+  }, [EMAIL PROTECTED], 90);
 
-  foreach (@wait_how) {
-    $test = "cond_timedwait instant timeout [$_]";
-    threads->create(\&ctw_fail, -60)->join;
-    $Base += 2;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_timedwait instant timeout [$_]";
+      threads->create(\&ctw_fail, -60)->join;
+      $Base += 2;
+    }
+  }, [EMAIL PROTECTED], 90);
 
   # cond_timedwait timeout (relative timeout)
   sub ctw_fail {
@@ -189,11 +239,13 @@
   }
 
   # - TEST cond_wait
-  foreach (@wait_how) {
-    $test = "cond_wait [$_]";
-    threads->create(\&cw2)->join;
-    $Base += 6;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_wait [$_]";
+      threads->create(\&cw2)->join;
+      $Base += 6;
+    }
+  }, [EMAIL PROTECTED], 90);
 
   sub cw2 {
     my $thr;
@@ -218,11 +270,13 @@
 
   # - TEST cond_timedwait success
 
-  foreach (@wait_how) {
-    $test = "cond_timedwait [$_]";
-    threads->create(\&ctw2, 5)->join;
-    $Base += 6;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_timedwait [$_]";
+      threads->create(\&ctw2, 5)->join;
+      $Base += 6;
+    }
+  }, [EMAIL PROTECTED], 90);
 
   sub ctw2($) {
     my $to = shift;
@@ -249,17 +303,21 @@
 
   # - TEST cond_timedwait timeout
 
-  foreach (@wait_how) {
-    $test = "cond_timedwait pause, timeout [$_]";
-    threads->create(\&ctw_fail2, 3)->join;
-    $Base += 2;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_timedwait pause, timeout [$_]";
+      threads->create(\&ctw_fail2, 3)->join;
+      $Base += 2;
+    }
+  }, [EMAIL PROTECTED], 90);
 
-  foreach (@wait_how) {
-    $test = "cond_timedwait instant timeout [$_]";
-    threads->create(\&ctw_fail2, -60)->join;
-    $Base += 2;
-  }
+  forko( sub {
+    foreach (@wait_how) {
+      $test = "cond_timedwait instant timeout [$_]";
+      threads->create(\&ctw_fail2, -60)->join;
+      $Base += 2;
+    }
+  }, [EMAIL PROTECTED], 90);
 
   sub ctw_fail2 {
     my $to = shift;
End of Patch.

Reply via email to