d6f69ce0d9d4893afd7cf6f9f47716c6a21a31d7
[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     $ENV{PERL_DESTRUCT_LEVEL} = 0;      # XXX known trouble with global destruction
12 }
13 $| = 1;
14 print "1..12\n";
15 use Thread;
16 print "ok 1\n";
17
18 sub content
19 {
20  print shift;
21  return shift;
22 }
23
24 # create a thread passing args and immedaietly wait for it.
25 my $t = new Thread \&content,("ok 2\n","ok 3\n");
26 print $t->join;
27
28 # check that lock works ...
29 {lock $foo;
30  $t = new Thread sub { lock $foo; print "ok 5\n" };
31  print "ok 4\n";
32 }
33 $t->join;
34
35 sub islocked
36 {
37  my $val = shift;
38  my $ret;
39  print $val;
40  if (@_)
41   {
42    $ret = Thread->new(\&islocked, @_);
43    $ret->join;
44   }
45 }
46
47 $t = new Thread \&islocked, map { "ok $_\n" } 6..10;
48 $t->join;
49
50 # test that sleep lets other thread run
51 $t = new Thread \&islocked,"ok 11\n";
52 sleep 6;
53 print "ok 12\n";
54 $t->join;