perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gisle Aas <gi...@ActiveState.com>
Subject Re: [PATCH] libperl leaks a THREAD_KEY each time it is reloaded
Date Tue, 11 Jan 2005 18:42:53 GMT
Stas Bekman <stas@stason.org> writes:

> I can't figure out whether PL_thr_key is a static global that survives
> perl_destruct and perl_free?

It is. because you find it declared in perlvars.h under the following
heading:
---------------------------------------------------------->%-------------
/****************/
/* Truly global */
/****************/

/* Don't forget to re-run embed.pl to propagate changes! */

/* This file describes the "global" variables used by perl
 * This used to be in perl.h directly but we want to abstract out into
 * distinct files which are per-thread, per-interpreter or really global,
 * and how they're initialized.
 *
 * The 'G' prefix is only needed for vars that need appropriate #defines
 * generated in embed*.h.  Such symbols are also used to generate
 * the appropriate export list for win32. */

/* global state */
PERLVAR(Gcurinterp,     PerlInterpreter *)
                                        /* currently running interpreter
                                         * (initial parent interpreter under
                                         * useithreads) */
#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
PERLVAR(Gthr_key,       perl_key)       /* key to retrieve per-thread struct */
#endif

[...]

> If it does than this should work:
> 
> Index: src/modules/perl/mod_perl.c
> ===================================================================
> --- src/modules/perl/mod_perl.c	(revision 124805)
> +++ src/modules/perl/mod_perl.c	(working copy)
> @@ -573,6 +573,19 @@
>       MP_threads_started = 0;
>       MP_post_post_config_phase = 0;
> 
> +    /* with USE_ITHREADS perl leaks pthread_key_t on every
> +     * perl_destruct, which becomes a problem restarts: if the OS
> +     * limit is 1024, 1024 restarts later things will start
> +     * crashing */
> +    /* XXX: this is a workaround for the bug in perl, once and if it's
> +     * fixed we need to disable it for the versions that have it
> +     * fixed */
> +#ifdef ALLOC_THREAD_KEY
> +    if (PL_thr_key) {
> +        FREE_THREAD_KEY;
> +    }
> +#endif
> +

This would only work if the perl code is never re-entered after this.
Is this really the case?

The '#ifdef ALLOC_THREAD_KEY' is wrong AFAICT; this macro will always
be defined.  Testing PL_thr_key as a boolean is outside of the spec of
what pthreads define. PL_curinterp will be set if the key has
initialized.  That's a better test.

Does things not work if you just drop in the "perl_fini" destructor I
provided in mod_perl.c?

> MP_TRACE_i(MP_FUNC, "mod_perl sys term\n");
> 
>       modperl_env_unload();

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message