summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/ext/Thread/list.t
blob: f13f4b266a4c98d5e476b2f5124ad2719a309ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use Thread qw(async);
use Thread::Semaphore;

my $sem = Thread::Semaphore->new(0);

$nthreads = 4;

for (my $i = 0; $i < $nthreads; $i++) {
    async {
     	my $tid = Thread->self->tid;
	print "thread $tid started...\n";
	$sem->down;
	print "thread $tid finishing\n";
    };
}

print "main: started $nthreads threads\n";
sleep 2;

my @list = Thread->list;
printf "main: Thread->list returned %d threads\n", scalar(@list);

foreach my $t (@list) {
    print "inspecting thread $t...\n";
    print "...deref is $$t\n";
    print "...flags = ", $t->flags, "\n";
    print "...tid = ", $t->tid, "\n";
}
print "main thread telling workers to finish off...\n";
$sem->up($nthreads);
OpenPOWER on IntegriCloud