* Re: [Guile-commits] GNU Guile branch, master, updated. v2.1.0-213-gb43e81d
[not found] <E1VRpou-0002qh-2M@vcs.savannah.gnu.org>
@ 2013-10-04 4:20 ` Mark H Weaver
2013-10-05 11:22 ` Andy Wingo
0 siblings, 1 reply; 2+ messages in thread
From: Mark H Weaver @ 2013-10-04 4:20 UTC (permalink / raw)
To: Andy Wingo; +Cc: guile-devel
Hi Andy,
"Andy Wingo" <wingo@pobox.com> writes:
> diff --git a/libguile/programs.c b/libguile/programs.c
> index 37130d0..5039d2a 100644
> --- a/libguile/programs.c
> +++ b/libguile/programs.c
> @@ -297,7 +297,7 @@ SCM_DEFINE (scm_program_bindings, "program-bindings", 1, 0, 0,
> }
> #undef FUNC_NAME
>
> -SCM_DEFINE (scm_program_sources, "program-sources", 1, 0, 0,
> +SCM_DEFINE (scm_program_sources, "%program-sources", 1, 0, 0,
> (SCM program),
> "")
> #define FUNC_NAME s_scm_program_sources
> @@ -365,32 +365,24 @@ scm_i_program_properties (SCM program)
> }
> #undef FUNC_NAME
>
> -static SCM
> -program_source (SCM program, size_t ip, SCM sources)
> +SCM
> +scm_program_source (SCM program, SCM ip, SCM sources)
> {
> - SCM source = SCM_BOOL_F;
> + static SCM program_source = SCM_BOOL_F;
>
> - while (!scm_is_null (sources)
> - && scm_to_size_t (scm_caar (sources)) <= ip)
> - {
> - source = scm_car (sources);
> - sources = scm_cdr (sources);
> - }
> -
> - return source; /* (addr . (filename . (line . column))) */
> -}
> + if (scm_is_false (program_source)) {
> + if (!scm_module_system_booted_p)
> + return SCM_BOOL_F;
> +
> + program_source =
> + scm_c_private_variable ("system vm program", "program-source");
> + }
This lazy initialization pattern is not safe on modern weakly ordered
memory architectures. I've already raised this issue on the mailing
list more than once, and I've been trying to fix these bugs wherever I
can find them, but they are non-trivial to search for. Please do not
add more.
We need to either use a mutex to guard both reads and writes of
'program_source' (including the "scm_is_false (program_source)" check),
or we need to arrange for 'program_source' to be initialized during
guile's initialization before any other threads are created.
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread