Revision history for Perl extension threads.
+1.53 Mon Nov 27 12:08:27 EST 2006
+ - Fix for a thread cloning bug
+ - Fixes to test suite
+
1.52 Tue Nov 21 11:04:03 EST 2006
- Fix compiler warnings
-threads version 1.52
+threads version 1.53
====================
This module exposes interpreter threads to the Perl level.
BEGIN {
$| = 1;
- print("1..32\n"); ### Number of tests that will be run ###
+ print("1..82\n"); ### Number of tests that will be run ###
};
use threads;
$Base += 4;
}
+
# test cond_signal()
{
my $lock : shared;
$tr->join();
$Base += 5;
-
}
ok(2, $$r == 33, "cond_broadcast: ref: all three threads woken");
$Base += 2;
-
}
cond_broadcast($lock);
ok(4, $warncount == 2, 'get no warning on cond_broadcast');
- #$Base += 4;
+ $Base += 4;
+}
+
+
+# Stress test
+{
+ my $cnt = 50;
+
+ my $mutex = 1;
+ share($mutex);
+
+ my @threads;
+ for (1..$cnt) {
+ my $thread = threads->create(sub {
+ my $arg = $_;
+ my $result = 0;
+ for (0..1000000) {
+ $result++;
+ }
+ lock($mutex);
+ while ($mutex != $_) {
+ cond_wait($mutex);
+ }
+ $mutex++;
+ cond_broadcast($mutex);
+ return $result;
+ });
+ push(@threads, $thread);
+ }
+
+ for (1..$cnt) {
+ my $result = $threads[$_-1]->join();
+ ok($_, defined($result) && ("$result" eq '1000001'), "stress test - iter $_");
+ }
+
+ $Base += $cnt;
}
# EOF
ok(! defined($rc), 'Exited: threads->exit()');
-run_perl(prog => 'use threads 1.52;' .
+run_perl(prog => 'use threads 1.53;' .
'threads->exit(86);' .
'exit(99);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
ok(! defined($rc), 'Exited: $thr->set_thread_exit_only');
-run_perl(prog => 'use threads 1.52 qw(exit thread_only);' .
+run_perl(prog => 'use threads 1.53 qw(exit thread_only);' .
'threads->create(sub { exit(99); })->join();' .
'exit(86);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
is($?>>8, 86, "'use threads 'exit' => 'thread_only'");
-my $out = run_perl(prog => 'use threads 1.52;' .
+my $out = run_perl(prog => 'use threads 1.53;' .
'threads->create(sub {' .
' exit(99);' .
'})->join();' .
like($out, '1 finished and unjoined', "exit(status) in thread");
-$out = run_perl(prog => 'use threads 1.52 qw(exit thread_only);' .
+$out = run_perl(prog => 'use threads 1.53 qw(exit thread_only);' .
'threads->create(sub {' .
' threads->set_thread_exit_only(0);' .
' exit(99);' .
like($out, '1 finished and unjoined', "set_thread_exit_only(0)");
-run_perl(prog => 'use threads 1.52;' .
+run_perl(prog => 'use threads 1.53;' .
'threads->create(sub {' .
' $SIG{__WARN__} = sub { exit(99); };' .
' die();' .
use threads;
BEGIN {
- eval {
- require threads::shared;
- import threads::shared;
- };
- if ($@ || ! $threads::shared::threads_shared) {
- print("1..0 # Skip: threads::shared not available\n");
- exit(0);
- }
-
$| = 1;
print("1..12\n"); ### Number of tests that will be run ###
};
$localtime{$_} = localtime($_);
};
-my $mutex = 2;
-share($mutex);
-
my @threads;
for (0..$i) {
my $thread = threads->create(sub {
$error++;
}
}
- lock($mutex);
- while ($mutex != ($_ + 2)) {
- cond_wait($mutex);
- }
- ok($mutex, ! $error, 'localtime safe');
- $mutex++;
- cond_broadcast($mutex);
+ return $error;
});
push @threads, $thread;
}
-for (@threads) {
- $_->join();
+for (0..$i) {
+ my $result = $threads[$_]->join();
+ ok($_ + 2, defined($result) && ("$result" eq '0'), 'localtime safe');
}
# EOF
BEGIN {
$| = 1;
- print("1..63\n"); ### Number of tests that will be run ###
+ print("1..31\n"); ### Number of tests that will be run ###
};
use threads;
### Start of Testing ###
-sub test9 {
+my $cnt = 30;
+
+sub stress_re {
my $s = "abcd" x (1000 + $_[0]);
my $t = '';
while ($s =~ /(.)/g) { $t .= $1 }
- print "not ok $_[0]\n" if $s ne $t;
+ return ($s eq $t) ? 'ok' : 'not';
}
+
my @threads;
-for (2..32) {
- ok($_, 1, "Multiple thread test");
- push(@threads, threads->create('test9',$_));
+for (1..$cnt) {
+ push(@threads, threads->create('stress_re', $_));
}
-my $i = 33;
-for (@threads) {
- $_->join;
- ok($i++, 1, "Thread joined");
+for (1..$cnt) {
+ my $result = $threads[$_-1]->join;
+ ok($_+1, defined($result) && ($result eq 'ok'), "stress re - iter $_");
}
# EOF
# bugid #24165
-run_perl(prog => 'use threads 1.52;' .
+run_perl(prog => 'use threads 1.53;' .
'sub a{threads->create(shift)} $t = a sub{};' .
'$t->tid; $t->join; $t->tid',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
use strict;
use warnings;
-our $VERSION = '1.52';
+our $VERSION = '1.53';
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
=head1 VERSION
-This document describes threads version 1.52
+This document describes threads version 1.53
=head1 SYNOPSIS
L<http://www.cpanforum.com/dist/threads>
Annotated POD for L<threads>:
-L<http://annocpan.org/~JDHEDDEN/threads-1.52/threads.pm>
+L<http://annocpan.org/~JDHEDDEN/threads-1.53/threads.pm>
L<threads::shared>, L<perlthrtut>
SV *params)
{
ithread *thread;
- CLONE_PARAMS clone_param;
ithread *current_thread = S_ithread_get(aTHX);
SV **tmps_tmp = PL_tmps_stack;
* context for the duration of our work for new interpreter.
*/
{
+ CLONE_PARAMS clone_param;
+
dTHXa(thread->interp);
MY_CXT_CLONE;
SvREFCNT_dec(PL_endav);
PL_endav = newAV();
- clone_param.flags = 0;
+ clone_param.flags = 0;
if (SvPOK(init_function)) {
thread->init_function = newSV(0);
sv_copypv(thread->init_function, init_function);