}
use Config;
if (! $Config{'useithreads'}) {
- print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
+ print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
exit(0);
}
}
BEGIN {
$| = 1;
- print("1..82\n"); ### Number of tests that will be run ###
+ print("1..32\n"); ### Number of tests that will be run ###
};
use threads;
lock($counter);
if ($n > 0) {
$counter++;
- $th = threads->new(\&broad, $n-1);
+ $th = threads->create(\&broad, $n-1);
cond_wait($counter);
$counter += 10;
}
$th->join if $th;
}
- threads->new(\&broad, 3)->join;
+ threads->create(\&broad, 3)->join;
ok(2, $counter == 33, "cond_broadcast: all three threads woken");
$Base += 2;
lock($r);
if ($n > 0) {
$$r++;
- $th = threads->new(\&broad2, $n-1);
+ $th = threads->create(\&broad2, $n-1);
cond_wait($r);
$$r += 10;
}
$th->join if $th;
}
- threads->new(\&broad2, 3)->join;;
+ threads->create(\&broad2, 3)->join;;
ok(2, $$r == 33, "cond_broadcast: ref: all three threads woken");
$Base += 2;
$Base += 4;
}
-
-# Stress test
-{
- my $cnt = 50;
-
- my $mutex = 1;
- share($mutex);
-
- my @threads;
- for (1..$cnt) {
- $threads[$_] = threads->create(sub {
- my $arg = shift;
- my $result = 0;
- for (0..1000000) {
- $result++;
- }
- lock($mutex);
- while ($mutex != $arg) {
- cond_wait($mutex);
- }
- $mutex++;
- cond_broadcast($mutex);
- return $result;
- }, $_);
- }
-
- for (1..$cnt) {
- my $result = $threads[$_]->join();
- ok($_, defined($result) && ("$result" eq '1000001'), "stress test - iter $_");
- }
-
- $Base += $cnt;
-}
+exit(0);
# EOF