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