move op/ipc{msg,sem}.t into lib/ipc_sysv.t
[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 }
11}
12$| = 1;
13print "1..9\n";
14use Thread;
15print "ok 1\n";
16
17sub content
18{
19 print shift;
20 return shift;
21}
22
23# create a thread passing args and immedaietly wait for it.
24my $t = new Thread \&content,("ok 2\n","ok 3\n");
25print $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
34sub islocked
35{
36 use attrs 'locked';
37 my $val = shift;
38 my $ret;
39 if (@_)
40 {
41 $ret = new Thread \&islocked,shift;
42 sleep 2;
43 }
44 print $val;
45}
46
47$t = islocked("ok 6\n","ok 7\n");
48join $t;
49
50# test that sleep lets other thread run
51$t = new Thread \&islocked,"ok 8\n";
61bb5906 52sleep 6;
bf3d9ec5 53print "ok 9";
54join $t;