f8f82d20593660751e6775ed59a09c7005b193e0
[p5sagit/p5-mst-13.2.git] / ext / threads / t / list.t
1
2 BEGIN {
3     chdir 't' if -d 't';
4     push @INC, '../lib';
5     require Config; import Config;
6     unless ($Config{'useithreads'}) {
7         print "1..0 # Skip: no useithreads\n";
8         exit 0;
9     }
10 }
11
12 use ExtUtils::testlib;
13
14 use strict;
15
16
17 BEGIN { $| = 1; print "1..8\n" };
18 use threads;
19
20
21
22 print "ok 1\n";
23
24
25 #########################
26 sub ok {        
27     my ($id, $ok, $name) = @_;
28
29     # You have to do it this way or VMS will get confused.
30     print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
31
32     printf "# Failed test at line %d\n", (caller)[2] unless $ok;
33
34     return $ok;
35 }
36
37 ok(2, scalar @{[threads->list]} == 0,'');
38
39
40
41 threads->create(sub {})->join();
42 ok(3, scalar @{[threads->list]} == 0,'');
43
44 my $thread = threads->create(sub {});
45 ok(4, scalar @{[threads->list]} == 1,'');
46 $thread->join();
47 ok(5, scalar @{[threads->list]} == 0,'');
48
49 $thread = threads->create(sub { ok(6, threads->self == (threads->list)[0],'')});
50 threads->yield; # help out non-preemptive thread implementations
51 sleep 1;
52 ok(7, $thread == (threads->list)[0],'');
53 $thread->join();
54 ok(8, scalar @{[threads->list]} == 0,'');