This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test changes
[perl5.git] / t / lib / thread.t
CommitLineData
bf3d9ec5
NIS
1#!perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require Config; import Config;
7 if ($Config{'ccflags'} !~ /-DUSE_THREADS\b/) {
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";
52sleep 2;
53print "ok 9";
54join $t;