Skip to content

Commit

Permalink
Upgrade to threads 2.06
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhedden authored and rjbs committed Apr 30, 2016
1 parent 8a355c1 commit d9262b3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Porting/Maintainers.pl
Expand Up @@ -1187,7 +1187,7 @@ package Maintainers;
},

'threads' => {
'DISTRIBUTION' => 'JDHEDDEN/threads-2.02.tar.gz',
'DISTRIBUTION' => 'JDHEDDEN/threads-2.06.tar.gz',
'FILES' => q[dist/threads],
'EXCLUDED' => [
qr{^examples/},
Expand Down
17 changes: 9 additions & 8 deletions dist/threads/lib/threads.pm
Expand Up @@ -134,7 +134,7 @@ threads - Perl interpreter-based threads
=head1 VERSION
This document describes threads version 2.02
This document describes threads version 2.06
=head1 WARNING
Expand Down Expand Up @@ -363,10 +363,10 @@ If you add the C<stringify> import option to your C<use threads> declaration,
then using a threads object in a string or a string context (e.g., as a hash
key) will cause its ID to be used as the value:
use threads qw(stringify);
use threads qw(stringify);
my $thr = threads->create(...);
print("Thread $thr started...\n"); # Prints: Thread 1 started...
my $thr = threads->create(...);
print("Thread $thr started\n"); # Prints: Thread 1 started
=item threads->object($tid)
Expand Down Expand Up @@ -691,16 +691,17 @@ threaded applications.
To specify a particular stack size for any individual thread, call
C<-E<gt>create()> with a hash reference as the first argument:
my $thr = threads->create({'stack_size' => 32*4096}, \&foo, @args);
my $thr = threads->create({'stack_size' => 32*4096},
\&foo, @args);
=item $thr2 = $thr1->create(FUNCTION, ARGS)
This creates a new thread (C<$thr2>) that inherits the stack size from an
existing thread (C<$thr1>). This is shorthand for the following:
my $stack_size = $thr1->get_stack_size();
my $thr2 = threads->create({'stack_size' => $stack_size},
FUNCTION, ARGS);
my $stack_size = $thr1->get_stack_size();
my $thr2 = threads->create({'stack_size' => $stack_size},
FUNCTION, ARGS);
=back
Expand Down
10 changes: 5 additions & 5 deletions dist/threads/t/exit.t
Expand Up @@ -48,7 +48,7 @@ my $rc = $thr->join();
ok(! defined($rc), 'Exited: threads->exit()');


run_perl(prog => 'use threads 2.02;' .
run_perl(prog => 'use threads 2.06;' .
'threads->exit(86);' .
'exit(99);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
Expand Down Expand Up @@ -98,7 +98,7 @@ $rc = $thr->join();
ok(! defined($rc), 'Exited: $thr->set_thread_exit_only');


run_perl(prog => 'use threads 2.02 qw(exit thread_only);' .
run_perl(prog => 'use threads 2.06 qw(exit thread_only);' .
'threads->create(sub { exit(99); })->join();' .
'exit(86);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
Expand All @@ -108,7 +108,7 @@ run_perl(prog => 'use threads 2.02 qw(exit thread_only);' .
is($?>>8, 86, "'use threads 'exit' => 'thread_only'");
}

my $out = run_perl(prog => 'use threads 2.02;' .
my $out = run_perl(prog => 'use threads 2.06;' .
'threads->create(sub {' .
' exit(99);' .
'});' .
Expand All @@ -124,7 +124,7 @@ my $out = run_perl(prog => 'use threads 2.02;' .
like($out, qr/1 finished and unjoined/, "exit(status) in thread");


$out = run_perl(prog => 'use threads 2.02 qw(exit thread_only);' .
$out = run_perl(prog => 'use threads 2.06 qw(exit thread_only);' .
'threads->create(sub {' .
' threads->set_thread_exit_only(0);' .
' exit(99);' .
Expand All @@ -141,7 +141,7 @@ $out = run_perl(prog => 'use threads 2.02 qw(exit thread_only);' .
like($out, qr/1 finished and unjoined/, "set_thread_exit_only(0)");


run_perl(prog => 'use threads 2.02;' .
run_perl(prog => 'use threads 2.06;' .
'threads->create(sub {' .
' $SIG{__WARN__} = sub { exit(99); };' .
' die();' .
Expand Down
2 changes: 1 addition & 1 deletion dist/threads/t/thread.t
Expand Up @@ -161,7 +161,7 @@ package main;

# bugid #24165

run_perl(prog => 'use threads 2.02;' .
run_perl(prog => 'use threads 2.06;' .
'sub a{threads->create(shift)} $t = a sub{};' .
'$t->tid; $t->join; $t->tid',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
Expand Down
28 changes: 13 additions & 15 deletions dist/threads/threads.xs
Expand Up @@ -20,13 +20,12 @@
#endif
#ifdef HAS_PPPORT_H
# define NEED_PL_signals
# define NEED_newRV_noinc
# define NEED_sv_2pv_flags
# include "ppport.h"
# include "threads.h"
#endif
#ifndef sv_dup_inc
# define sv_dup_inc(s,t) SvREFCNT_inc(sv_dup(s,t))
# define sv_dup_inc(s,t) SvREFCNT_inc(sv_dup(s,t))
#endif
#ifndef PERL_UNUSED_RESULT
# if defined(__GNUC__) && defined(HASATTRIBUTE_WARN_UNUSED_RESULT)
Expand Down Expand Up @@ -476,13 +475,13 @@ S_good_stack_size(pTHX_ IV stack_size)
return (stack_size);
}

/* run some code within a JMPENV environment.
* Having it in a separate small function helps avoid
* 'variable ‘foo’ might be clobbered by ‘longjmp’

/* Run code within a JMPENV environment.
* Using a separate function avoids
* "variable 'foo' might be clobbered by 'longjmp'"
* warnings.
* The three _p vars return values to the caller
*/

static int
S_jmpenv_run(pTHX_ int action, ithread *thread,
int *len_p, int *exit_app_p, int *exit_code_p)
Expand All @@ -496,12 +495,10 @@ S_jmpenv_run(pTHX_ int action, ithread *thread,
if (action == 0) {
/* Run the specified function */
*len_p = (int)call_sv(thread->init_function, thread->gimme|G_EVAL);
}
else if (action == 1) {
} else if (action == 1) {
/* Warn that thread died */
Perl_warn(aTHX_ "Thread %" UVuf " terminated abnormally: %" SVf, thread->tid, ERRSV);
}
else {
} else {
/* Warn if there are unjoined threads */
S_exit_warning(aTHX);
}
Expand Down Expand Up @@ -1018,8 +1015,9 @@ S_ithread_create(
my_pool->running_threads++;
MUTEX_UNLOCK(&my_pool->create_destruct_mutex);
return (thread);
CLANG_DIAG_IGNORE(-Wthread-safety);
/* warning: mutex 'thread->mutex' is not held on every path through here [-Wthread-safety-analysis] */

CLANG_DIAG_IGNORE(-Wthread-safety);
/* warning: mutex 'thread->mutex' is not held on every path through here [-Wthread-safety-analysis] */
}
#if defined(__clang__) || defined(__clang)
CLANG_DIAG_RESTORE;
Expand Down Expand Up @@ -1161,10 +1159,10 @@ ithread_create(...)

/* Let thread run. */
/* See S_ithread_run() for more detail. */
CLANG_DIAG_IGNORE(-Wthread-safety);
/* warning: releasing mutex 'thread->mutex' that was not held [-Wthread-safety-analysis] */
CLANG_DIAG_IGNORE(-Wthread-safety);
/* warning: releasing mutex 'thread->mutex' that was not held [-Wthread-safety-analysis] */
MUTEX_UNLOCK(&thread->mutex);
CLANG_DIAG_RESTORE;
CLANG_DIAG_RESTORE;

/* XSRETURN(1); - implied */

Expand Down

0 comments on commit d9262b3

Please sign in to comment.