unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: "Andy Wingo" <wingo@pobox.com>
Cc: guile-devel@gnu.org
Subject: Re: [Guile-commits] GNU Guile branch, master, updated. v2.1.0-213-gb43e81d
Date: Fri, 04 Oct 2013 00:20:46 -0400	[thread overview]
Message-ID: <87bo35bra9.fsf@netris.org> (raw)
In-Reply-To: <E1VRpou-0002qh-2M@vcs.savannah.gnu.org> (Andy Wingo's message of "Thu, 03 Oct 2013 20:48:24 +0000")

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



       reply	other threads:[~2013-10-04  4:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1VRpou-0002qh-2M@vcs.savannah.gnu.org>
2013-10-04  4:20 ` Mark H Weaver [this message]
2013-10-05 11:22   ` [Guile-commits] GNU Guile branch, master, updated. v2.1.0-213-gb43e81d Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bo35bra9.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).