threads 1.66
[p5sagit/p5-mst-13.2.git] / ext / threads / t / stress_cv.t
CommitLineData
0f1612a7 1use strict;
2use warnings;
3
3dbf27b4 4BEGIN {
0f1612a7 5 if ($ENV{'PERL_CORE'}){
6 chdir 't';
7 unshift @INC, '../lib';
8 }
9 use Config;
fc04eb16 10 if (! $Config{'useithreads'}) {
11 print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
12 exit(0);
3dbf27b4 13 }
14}
15
16use ExtUtils::testlib;
0f1612a7 17
a662d730 18my $test = 0;
fc04eb16 19sub ok {
a662d730 20 my ($ok, $name) = @_;
21 $test++;
fc04eb16 22
3dbf27b4 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 }
3dbf27b4 30
fc04eb16 31 return ($ok);
3dbf27b4 32}
33
fc04eb16 34BEGIN {
35 $| = 1;
a662d730 36 print("1..61\n"); ### Number of tests that will be run ###
fc04eb16 37};
3dbf27b4 38
fc04eb16 39use threads;
a662d730 40ok(1, 'Loaded');
3dbf27b4 41
fc04eb16 42### Start of Testing ###
3dbf27b4 43
a662d730 44my $cnt = 30;
45
3dbf27b4 46my @threads;
a662d730 47for (1..$cnt) {
48 my $thr = threads->create(sub { my $ii = shift;
49 for (1..500000) { $ii++ } }, $_);
50 ok($thr, "Thread created - iter $_");
51 push(@threads, $thr);
3dbf27b4 52}
53
a662d730 54for (1..$cnt) {
55 my ($result, $thr);
56 $thr = $threads[$_-1];
57 $result = $thr->join if $thr;
58 ok($thr, "Thread joined - iter $_");
3dbf27b4 59}
60
fc04eb16 61# EOF