Protect the (original) thread tests against testing if no 5.005
[p5sagit/p5-mst-13.2.git] / ext / Thread / list.t
1 BEGIN {
2     eval { require Config; import Config };
3     if ($@) {
4         print "1..0 # Skip: no Config\n";
5         exit(0);
6     }
7     if ($Config{extensions} !~ /\bThread\b/) {
8         print "1..0 # Skip: no use5005threads\n";
9         exit(0);
10     }
11 }
12
13 use Thread qw(async);
14 use Thread::Semaphore;
15
16 my $sem = Thread::Semaphore->new(0);
17
18 $nthreads = 4;
19
20 for (my $i = 0; $i < $nthreads; $i++) {
21     async {
22         my $tid = Thread->self->tid;
23         print "thread $tid started...\n";
24         $sem->down;
25         print "thread $tid finishing\n";
26     };
27 }
28
29 print "main: started $nthreads threads\n";
30 sleep 2;
31
32 my @list = Thread->list;
33 printf "main: Thread->list returned %d threads\n", scalar(@list);
34
35 foreach my $t (@list) {
36     print "inspecting thread $t...\n";
37     print "...deref is $$t\n";
38     print "...flags = ", $t->flags, "\n";
39     print "...tid = ", $t->tid, "\n";
40 }
41 print "main thread telling workers to finish off...\n";
42 $sem->up($nthreads);