blob: 5c25dae736fda2bbf5b8754e55b15754854b1102 (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
use strict;
use warnings;
BEGIN {
use Config;
if (! $Config{'useithreads'}) {
print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
exit(0);
}
}
use ExtUtils::testlib;
my $test = 0;
sub ok {
my ($ok, $name) = @_;
$test++;
# You have to do it this way or VMS will get confused.
if ($ok) {
print("ok $test - $name\n");
} else {
print("not ok $test - $name\n");
printf("# Failed test at line %d\n", (caller)[2]);
}
return ($ok);
}
BEGIN {
$| = 1;
print("1..61\n"); ### Number of tests that will be run ###
};
use threads;
ok(1, 'Loaded');
### Start of Testing ###
my $cnt = 30;
sub stress_re {
my $s = "abcd" x (1000 + $_[0]);
my $t = '';
while ($s =~ /(.)/g) { $t .= $1 }
return ($s eq $t) ? 'ok' : 'not';
}
my @threads;
for (1..$cnt) {
my $thr = threads->create('stress_re', $_);
ok($thr, "Thread created - iter $_");
push(@threads, $thr);
}
for (1..$cnt) {
my ($result, $thr);
$thr = $threads[$_-1];
$result = $thr->join if $thr;
ok($thr && defined($result) && ($result eq 'ok'), "Thread joined - iter $_");
}
exit(0);
# EOF
|