Rename ext/threads/shared to ext/threads-shared
[p5sagit/p5-mst-13.2.git] / ext / threads / t / stress_re.t
CommitLineData
0f1612a7 1use strict;
2use warnings;
3
31623e47 4BEGIN {
0f1612a7 5 if ($ENV{'PERL_CORE'}){
6 chdir 't';
7 unshift @INC, '../lib';
8 }
9 use Config;
fc04eb16 10 if (! $Config{'useithreads'}) {
561ee912 11 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
fc04eb16 12 exit(0);
31623e47 13 }
14}
15
16use ExtUtils::testlib;
0f1612a7 17
a662d730 18my $test = 0;
fc04eb16 19sub ok {
a662d730 20 my ($ok, $name) = @_;
21 $test++;
fc04eb16 22
31623e47 23 # You have to do it this way or VMS will get confused.
fc04eb16 24 if ($ok) {
a662d730 25 print("ok $test - $name\n");
fc04eb16 26 } else {
a662d730 27 print("not ok $test - $name\n");
fc04eb16 28 printf("# Failed test at line %d\n", (caller)[2]);
29 }
31623e47 30
fc04eb16 31 return ($ok);
31623e47 32}
33
fc04eb16 34BEGIN {
35 $| = 1;
a662d730 36 print("1..61\n"); ### Number of tests that will be run ###
fc04eb16 37};
38
39use threads;
a662d730 40ok(1, 'Loaded');
31623e47 41
fc04eb16 42### Start of Testing ###
31623e47 43
894eec8b 44my $cnt = 30;
45
46sub stress_re {
fc04eb16 47 my $s = "abcd" x (1000 + $_[0]);
48 my $t = '';
49 while ($s =~ /(.)/g) { $t .= $1 }
894eec8b 50 return ($s eq $t) ? 'ok' : 'not';
31623e47 51}
894eec8b 52
31623e47 53my @threads;
894eec8b 54for (1..$cnt) {
a662d730 55 my $thr = threads->create('stress_re', $_);
56 ok($thr, "Thread created - iter $_");
57 push(@threads, $thr);
31623e47 58}
59
894eec8b 60for (1..$cnt) {
a662d730 61 my ($result, $thr);
62 $thr = $threads[$_-1];
63 $result = $thr->join if $thr;
64 ok($thr && defined($result) && ($result eq 'ok'), "Thread joined - iter $_");
31623e47 65}
66
561ee912 67exit(0);
68
fc04eb16 69# EOF