Protect the (original) thread tests against testing if no 5.005
[p5sagit/p5-mst-13.2.git] / ext / Thread / list.t
CommitLineData
0fcb073c 1BEGIN {
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
0a00ffdb 13use Thread qw(async);
14use Thread::Semaphore;
15
16my $sem = Thread::Semaphore->new(0);
17
18$nthreads = 4;
19
20for (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
29print "main: started $nthreads threads\n";
30sleep 2;
31
32my @list = Thread->list;
33printf "main: Thread->list returned %d threads\n", scalar(@list);
34
35foreach 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}
41print "main thread telling workers to finish off...\n";
42$sem->up($nthreads);