fix thread.t ('join $t' ne '$t->join' !)
[p5sagit/p5-mst-13.2.git] / t / lib / thread.t
CommitLineData
39e571d4 1#!./perl
bf3d9ec5 2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require Config; import Config;
dfe9444c 7 if (! $Config{'usethreads'}) {
bf3d9ec5 8 print "1..0\n";
9 exit 0;
10 }
eec2d3df 11 $ENV{PERL_DESTRUCT_LEVEL} = 0; # XXX known trouble with global destruction
bf3d9ec5 12}
13$| = 1;
0f5feb8d 14print "1..12\n";
bf3d9ec5 15use Thread;
16print "ok 1\n";
17
18sub content
19{
20 print shift;
21 return shift;
22}
23
24# create a thread passing args and immedaietly wait for it.
25my $t = new Thread \&content,("ok 2\n","ok 3\n");
26print $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
35sub islocked
36{
bf3d9ec5 37 my $val = shift;
38 my $ret;
0f5feb8d 39 print $val;
bf3d9ec5 40 if (@_)
41 {
0f5feb8d 42 $ret = Thread->new(\&islocked, @_);
faa19ec9 43 $ret->join;
bf3d9ec5 44 }
bf3d9ec5 45}
46
0f5feb8d 47$t = new Thread \&islocked, map { "ok $_\n" } 6..10;
faa19ec9 48$t->join;
bf3d9ec5 49
50# test that sleep lets other thread run
0f5feb8d 51$t = new Thread \&islocked,"ok 11\n";
61bb5906 52sleep 6;
0f5feb8d 53print "ok 12\n";
faa19ec9 54$t->join;