Skip to content

Commit

Permalink
threads v1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhedden committed Apr 21, 2016
1 parent 958ef16 commit a6e52fa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Revision history for Perl extension threads.

1.24 Mon Apr 24 10:29:11 EDT 2006
- assert() that thread 0 is never destructed
- Determinancy in free.t

1.23 Thu Apr 13 16:57:00 EDT 2006
- BUG (RE)FIX: Properly free thread's Perl interpreter
- It's an error to detach a thread twice
Expand Down
52 changes: 29 additions & 23 deletions t/free.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,24 @@ BEGIN {

use ExtUtils::testlib;

use threads;
use threads::shared;

BEGIN {
$| = 1;
print("1..29\n"); ### Number of tests that will be run ###
};

my $TEST = 1;
share($TEST);

ok(1, 'Loaded');

sub ok {
my ($id, $ok, $name) = @_;
my ($ok, $name) = @_;

lock($TEST);
my $id = $TEST++;

# You have to do it this way or VMS will get confused.
if ($ok) {
Expand All @@ -29,14 +45,6 @@ sub ok {
return ($ok);
}

BEGIN {
$| = 1;
print("1..29\n"); ### Number of tests that will be run ###
};

use threads;
use threads::shared;
ok(1, 1, 'Loaded');

### Start of Testing ###

Expand All @@ -45,12 +53,10 @@ ok(1, 1, 'Loaded');

my $COUNT;
share($COUNT);
my $TEST = 2;
share($TEST);

sub threading_1 {
my $tid = threads->tid();
ok($TEST++, $tid, "Thread $tid started");
ok($tid, "Thread $tid started");

if ($tid < 5) {
sleep(1);
Expand All @@ -74,7 +80,7 @@ sub threading_1 {
lock($COUNT);
$COUNT++;
cond_signal($COUNT);
ok($TEST++, $tid, "Thread $tid done");
ok($tid, "Thread $tid done");
}

{
Expand All @@ -97,12 +103,12 @@ sub threading_1 {
threads->yield();
sleep(1);
}
ok($TEST++, $COUNT == 5, "Done - $COUNT threads");
ok($COUNT == 5, "Done - $COUNT threads");


sub threading_2 {
my $tid = threads->tid();
ok($TEST++, $tid, "Thread $tid started");
ok($tid, "Thread $tid started");

if ($tid < 10) {
threads->create('threading_2')->detach();
Expand All @@ -114,7 +120,7 @@ sub threading_2 {
$COUNT++;
cond_signal($COUNT);

ok($TEST++, $tid, "Thread $tid done");
ok($tid, "Thread $tid done");
}

{
Expand All @@ -129,23 +135,23 @@ sub threading_2 {
threads->yield();
sleep(1);
}
ok($TEST++, $COUNT == 5, "Done - $COUNT threads");
ok($COUNT == 5, "Done - $COUNT threads");


{
threads->create(sub { })->join();
}
ok($TEST++, 1, 'Join');
ok(1, 'Join');


sub threading_3 {
my $tid = threads->tid();
ok($TEST++, $tid, "Thread $tid started");
ok($tid, "Thread $tid started");

{
threads->create(sub {
my $tid = threads->tid();
ok($TEST++, $tid, "Thread $tid started");
ok($tid, "Thread $tid started");

threads->yield();
sleep(1);
Expand All @@ -154,15 +160,15 @@ sub threading_3 {
$COUNT++;
cond_signal($COUNT);

ok($TEST++, $tid, "Thread $tid done");
ok($tid, "Thread $tid done");
})->join();
}

lock($COUNT);
$COUNT++;
cond_signal($COUNT);

ok($TEST++, $tid, "Thread $tid done");
ok($tid, "Thread $tid done");
}

{
Expand All @@ -179,6 +185,6 @@ sub threading_3 {
threads->yield();
sleep(1);
}
ok($TEST++, $COUNT == 2, "Done - $COUNT threads");
ok($COUNT == 2, "Done - $COUNT threads");

# EOF
10 changes: 7 additions & 3 deletions t/free2.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ BEGIN {

use ExtUtils::testlib;

use threads;
use threads::shared;

BEGIN {
if (($] < 5.008002) && ($threads::shared::VERSION < 0.92)) {
print("1..0 # Skip: Needs threads::shared 0.92 or later\n");
exit(0);
}

$| = 1;
print("1..74\n"); ### Number of tests that will be run ###
};

use threads;
use threads::shared;

my $TEST = 1;
share($TEST);

Expand Down
6 changes: 3 additions & 3 deletions threads.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use 5.008;
use strict;
use warnings;

our $VERSION = '1.23';
our $VERSION = '1.24';
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;

Expand Down Expand Up @@ -102,7 +102,7 @@ threads - Perl interpreter-based threads
=head1 VERSION
This document describes threads version 1.23
This document describes threads version 1.24
=head1 SYNOPSIS
Expand Down Expand Up @@ -505,7 +505,7 @@ L<threads> Discussion Forum on CPAN:
L<http://www.cpanforum.com/dist/threads>
Annotated POD for L<threads>:
L<http://annocpan.org/~JDHEDDEN/threads-1.23/shared.pm>
L<http://annocpan.org/~JDHEDDEN/threads-1.24/shared.pm>
L<threads::shared>, L<perlthrtut>
Expand Down
11 changes: 7 additions & 4 deletions threads.xs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ S_ithread_create(
SV **tmps_tmp = PL_tmps_stack;
IV tmps_ix = PL_tmps_ix;
#ifndef WIN32
int rc_thread_create = 0;
int rc_stack_size = 0;
int rc_thread_create = 0;
#endif

MUTEX_LOCK(&create_destruct_mutex);
Expand Down Expand Up @@ -518,7 +518,7 @@ S_ithread_create(
#ifdef WIN32
if (thread->handle == NULL) {
#else
if (rc_thread_create || rc_stack_size) {
if (rc_stack_size || rc_thread_create) {
#endif
MUTEX_UNLOCK(&create_destruct_mutex);
sv_2mortal(params);
Expand Down Expand Up @@ -589,8 +589,11 @@ S_ithread_destruct(pTHX_ ithread *thread)
return;
}

/* Remove from circular list of threads */
MUTEX_LOCK(&create_destruct_mutex);
/* Main thread (0) is immortal and should never get here */
assert(thread->tid != 0);

/* Remove from circular list of threads */
thread->next->prev = thread->prev;
thread->prev->next = thread->next;
thread->next = NULL;
Expand Down Expand Up @@ -626,7 +629,7 @@ Perl_ithread_hook(pTHX)
{
int veto_cleanup = 0;
MUTEX_LOCK(&create_destruct_mutex);
if ((aTHX == PL_curinterp) && (active_threads > 1)) {
if ((aTHX == PL_curinterp) && (active_threads != 1)) {
if (ckWARN_d(WARN_THREADS)) {
Perl_warn(aTHX_ "A thread exited while %" IVdf " threads were running", active_threads);
}
Expand Down

0 comments on commit a6e52fa

Please sign in to comment.