| 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; |
| 10 |
|
| 11 |
$| = 1; |
| 12 |
|
| 13 |
srand($$^$^T); |
| 14 |
|
| 15 |
sub printargs { |
| 16 |
my $thread = shift; |
| 17 |
my $arg; |
| 18 |
my $i; |
| 19 |
while ($arg = shift) { |
| 20 |
my $delay = int(rand(500)); |
| 21 |
$i++; |
| 22 |
print "$thread arg $i is $arg\n"; |
| 23 |
1 while $delay--; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
sub start_thread { |
| 28 |
my $thread = shift; |
| 29 |
my $count = 10; |
| 30 |
while ($count--) { |
| 31 |
my(@args) = ($thread) x int(rand(10)); |
| 32 |
print "$thread $count calling printargs @args\n"; |
| 33 |
printargs($thread, @args); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
new Thread (\&start_thread, "A"); |
| 38 |
new Thread (\&start_thread, "B"); |
| 39 |
#new Thread (\&start_thread, "C"); |
| 40 |
#new Thread (\&start_thread, "D"); |
| 41 |
#new Thread (\&start_thread, "E"); |
| 42 |
#new Thread (\&start_thread, "F"); |
| 43 |
|
| 44 |
print "main: exiting\n"; |