tweak t/lib/thread.t
[p5sagit/p5-mst-13.2.git] / t / lib / thread.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require Config; import Config;
7     if (! $Config{'usethreads'}) {
8         print "1..0\n";
9         exit 0;
10     }
11 }
12 $| = 1;
13 print "1..12\n";
14 use Thread;
15 print "ok 1\n";
16
17 sub content
18 {
19  print shift;
20  return shift;
21 }
22
23 # create a thread passing args and immedaietly wait for it.
24 my $t = new Thread \&content,("ok 2\n","ok 3\n");
25 print $t->join;
26
27 # check that lock works ...
28 {lock $foo;
29  $t = new Thread sub { lock $foo; print "ok 5\n" };
30  print "ok 4\n";
31 }
32 $t->join;
33
34 sub islocked
35 {
36  use attrs 'locked';
37  my $val = shift;
38  my $ret;
39  print $val;
40  if (@_)
41   {
42    $ret = Thread->new(\&islocked, @_);
43    join $ret;
44   }
45 }
46
47 $t = new Thread \&islocked, map { "ok $_\n" } 6..10;
48 sleep 2;
49 join $t;
50
51 # test that sleep lets other thread run
52 $t = new Thread \&islocked,"ok 11\n";
53 sleep 6;
54 print "ok 12\n";
55 join $t;