Skip to content

Commit eee5649

Browse files
committed
Use shutdown hook to destruct shared interpreter on program termination
1 parent db4b30a commit eee5649

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

dist/threads-shared/lib/threads/shared.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Config;
88

99
use Scalar::Util qw(reftype refaddr blessed);
1010

11-
our $VERSION = '1.69'; # Please update the pod, too.
11+
our $VERSION = '1.70'; # Please update the pod, too.
1212
my $XS_VERSION = $VERSION;
1313
$VERSION = eval $VERSION;
1414

@@ -196,7 +196,7 @@ threads::shared - Perl extension for sharing data structures between threads
196196
197197
=head1 VERSION
198198
199-
This document describes threads::shared version 1.68
199+
This document describes threads::shared version 1.70
200200
201201
=head1 SYNOPSIS
202202

dist/threads-shared/shared.xs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,21 @@ S_shared_signal_hook(pTHX) {
12841284
}
12851285
#endif
12861286

1287+
#ifdef noshutdownhook
1288+
1289+
static shutdown_proc_t old_shutdownhook;
1290+
1291+
static void
1292+
shared_shutdown() {
1293+
PerlInterpreter* my_perl;
1294+
SHARED_CONTEXT;
1295+
perl_destruct(PL_sharedsv_space);
1296+
perl_free(PL_sharedsv_space);
1297+
PL_sharedsv_space = NULL;
1298+
old_shutdownhook();
1299+
}
1300+
#endif
1301+
12871302
/* Saves a space for keeping SVs wider than an interpreter. */
12881303

12891304
static void
@@ -1299,6 +1314,12 @@ Perl_sharedsv_init(pTHX)
12991314
LEAVE; /* This balances the ENTER at the end of perl_construct. */
13001315
PERL_SET_CONTEXT((aTHX = caller_perl));
13011316
recursive_lock_init(aTHX_ &PL_sharedsv_lock);
1317+
#ifdef noshutdownhook
1318+
OP_CHECK_MUTEX_LOCK;
1319+
old_shutdownhook = PL_shutdownhook;
1320+
PL_shutdownhook = &shared_shutdown;
1321+
OP_CHECK_MUTEX_UNLOCK;
1322+
#endif
13021323
}
13031324
PL_lockhook = &Perl_sharedsv_locksv;
13041325
PL_sharehook = &Perl_sharedsv_share;

0 commit comments

Comments
 (0)