adjust timeouts to accomodate slow/busy systems
[p5sagit/p5-mst-13.2.git] / t / lib / thread.t
old mode 100644 (file)
new mode 100755 (executable)
index 798adc1..8d38523
@@ -1,16 +1,19 @@
-#!perl
+#!./perl
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = '../lib';
+    unshift @INC, '../lib';
     require Config; import Config;
-    if ($Config{'ccflags'} !~ /-DUSE_THREADS\b/) {
+    if (! $Config{'usethreads'}) {
        print "1..0\n";
        exit 0;
     }
+
+    # XXX known trouble with global destruction
+    $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
 }
 $| = 1;
-print "1..9\n";
+print "1..14\n";
 use Thread;
 print "ok 1\n";
 
@@ -31,24 +34,40 @@ print $t->join;
 }
 $t->join;
 
+sub dorecurse
+{
+ my $val = shift;
+ my $ret;
+ print $val;
+ if (@_)
+  {
+   $ret = Thread->new(\&dorecurse, @_);
+   $ret->join;
+  }
+}
+
+$t = new Thread \&dorecurse, map { "ok $_\n" } 6..10;
+$t->join;
+
+# test that sleep lets other thread run
+$t = new Thread \&dorecurse,"ok 11\n";
+sleep 6;
+print "ok 12\n";
+$t->join;
+
 sub islocked
 {
  use attrs 'locked';
  my $val = shift;
  my $ret;
+ print $val;
  if (@_)
   {
-   $ret = new Thread \&islocked,shift;
-   sleep 2;
+   $ret = Thread->new(\&islocked, shift);
   }
- print $val;
+ $ret;
 }
 
-$t = islocked("ok 6\n","ok 7\n");
-join $t;
+$t = Thread->new(\&islocked, "ok 13\n", "ok 14\n");
+$t->join->join;
 
-# test that sleep lets other thread run
-$t = new Thread \&islocked,"ok 8\n";
-sleep 2;
-print "ok 9";
-join $t;