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