| 1 |
root |
1.1 |
BEGIN { |
| 2 |
|
|
eval { require Config; import Config }; |
| 3 |
|
|
if ($@) { |
| 4 |
|
|
print "1..0 # Skip: no Config\n"; |
| 5 |
|
|
exit(0); |
| 6 |
|
|
} |
| 7 |
|
|
} |
| 8 |
|
|
|
| 9 |
|
|
use Thread qw(async); |
| 10 |
|
|
use Thread::Semaphore; |
| 11 |
|
|
|
| 12 |
|
|
my $sem = Thread::Semaphore->new(0); |
| 13 |
|
|
|
| 14 |
|
|
$nthreads = 4; |
| 15 |
|
|
|
| 16 |
|
|
for (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 |
|
|
|
| 25 |
|
|
print "main: started $nthreads threads\n"; |
| 26 |
|
|
sleep 2; |
| 27 |
|
|
|
| 28 |
|
|
my @list = Thread->list; |
| 29 |
|
|
printf "main: Thread->list returned %d threads\n", scalar(@list); |
| 30 |
|
|
|
| 31 |
|
|
foreach 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 |
|
|
} |
| 37 |
|
|
print "main thread telling workers to finish off...\n"; |
| 38 |
|
|
$sem->up($nthreads); |