threads::shared 1.13
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / waithires.t
index 8620ab5..22e9c73 100644 (file)
@@ -13,7 +13,7 @@ BEGIN {
     }
     eval {
         require Time::HiRes;
-        import Time::HiRes qw(time);
+        Time::HiRes->import('time');
     };
     if ($@) {
         print("1..0 # Skip: Time::HiRes not available.\n");
@@ -41,7 +41,7 @@ sub ok {
 
 BEGIN {
     $| = 1;
-    print("1..63\n");   ### Number of tests that will be run ###
+    print("1..57\n");   ### Number of tests that will be run ###
 };
 
 use threads;
@@ -64,6 +64,7 @@ $Base++;
 # RedHat users should see https://rhn.redhat.com/errata/RHBA-2003-136.html
 # and consider upgrading their glibc.
 
+
 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.
@@ -77,14 +78,11 @@ sub forko (&$$); # To prevent deadlock from underlying pthread_* bugs (as in
 
   my $bump = $expected;
 
-  $patience ||= 60;
-
   unless (defined($pid = open(CHLD, "-|"))) {
     die "fork: $!\n";
   }
   if (! $pid) {   # Child -- run the test
-    $patience ||= 60;
-    alarm $patience;
+    alarm($patience || 60);
     &$code;
     exit;
   }
@@ -98,14 +96,13 @@ sub forko (&$$); # To prevent deadlock from underlying pthread_* bugs (as in
   close(CHLD);
 
   while ($expected--) {
-    $test_num++;
-    print "not ok $test_num - child status $?\n";
+    ok(++$test_num, 0, "missing test result: child status $?");
   }
 
   $Base += $bump;
-
 };
 
+
 # - TEST basics
 
 my @wait_how = (
@@ -141,19 +138,18 @@ SYNC_SHARED: {
     foreach (@wait_how) {
       $test = "cond_timedwait [$_]";
       threads->create(\&ctw, 0.05)->join;
-      $Base += 6;
+      $Base += 5;
     }
-  }, 6*@wait_how, 5);
+  }, 5*@wait_how, 5);
 
   sub ctw($) {
-    my $to = shift;
-    my $thr;
+      my $to = shift;
 
-    { # -- begin lock scope;  which lock to obtain?
+      # which lock to obtain?
       $test =~ /twain/ ? lock($lock) : lock($cond);
       ok(1,1, "$test: obtained initial lock");
 
-      $thr = threads->create(\&signaller);
+      my $thr = threads->create(\&signaller);
       my $ok = 0;
       for ($test) {
         $ok=cond_timedwait($cond, time() + $to), last        if    /simple/;
@@ -161,11 +157,8 @@ SYNC_SHARED: {
         $ok=cond_timedwait($cond, time() + $to, $lock), last if    /twain/;
         die "$test: unknown test\n";
       }
+      $thr->join;
       ok(5,$ok, "$test: condition obtained");
-    } # -- end lock scope
-
-    $thr->join;
-    ok(6,1, "$test: join completed");
   }
 
   # - TEST cond_timedwait timeout
@@ -252,19 +245,18 @@ SYNCH_REFS: {
     foreach (@wait_how) {
       $test = "cond_timedwait [$_]";
       threads->create(\&ctw2, 0.05)->join;
-      $Base += 6;
+      $Base += 5;
     }
-  }, 6*@wait_how, 5);
+  }, 5*@wait_how, 5);
 
   sub ctw2($) {
-    my $to = shift;
-    my $thr;
+      my $to = shift;
 
-    { # -- begin lock scope;  which lock to obtain?
+      # which lock to obtain?
       $test =~ /twain/ ? lock($lock) : lock($cond);
       ok(1,1, "$test: obtained initial lock");
 
-      $thr = threads->create(\&signaller2);
+      my $thr = threads->create(\&signaller2);
       my $ok = 0;
       for ($test) {
         $ok=cond_timedwait($cond, time() + $to), last        if    /simple/;
@@ -272,11 +264,8 @@ SYNCH_REFS: {
         $ok=cond_timedwait($cond, time() + $to, $lock), last if    /twain/;
         die "$test: unknown test\n";
       }
+      $thr->join;
       ok(5,$ok, "$test: condition obtained");
-    } # -- end lock scope
-
-    $thr->join;
-    ok(6,1, "$test: join completed");
   }
 
   # - TEST cond_timedwait timeout