unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Linas Vepstas <INVALID.NOREPLY@gnu.org>
To: "Andy Wingo" <wingo@pobox.com>, "Ludovic Courtès" <ludo@gnu.org>,
	"Linas Vepstas" <linasvepstas@gmail.com>,
	bug-guile@gnu.org
Subject: [bug #24867] `define' should be thread-safe
Date: Tue, 23 Dec 2008 02:36:13 +0000	[thread overview]
Message-ID: <20081223-023612.sv71519.31021@savannah.gnu.org> (raw)
In-Reply-To: <20081118-132731.sv15145.42938@savannah.gnu.org>


Follow-up Comment #2, bug #24867 (project guile):


The following patch protects the update of the module hash tables
to be thread-safe. This is a partial solution to the bug reported 
in https://savannah.gnu.org/bugs/?24867 This is not a full solution,
because other threads might still be reading the hash tables while
they are being updated, and thus may obtain stale/bad data.

Signed-off-by: Linas Vepstas <linasvepstas@gmail.com>

---
 libguile/modules.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Index: guile-1.8.6/libguile/modules.c
===================================================================
--- guile-1.8.6.orig/libguile/modules.c	2008-12-22 18:38:41.000000000 -0600
+++ guile-1.8.6/libguile/modules.c	2008-12-22 20:22:19.000000000 -0600
@@ -555,11 +555,16 @@ scm_c_define (const char *name, SCM valu
   return scm_define (scm_from_locale_symbol (name), value);
 }
 
+scm_i_pthread_mutex_t scm_i_define_mutex;
+
 SCM
 scm_define (SCM sym, SCM value)
 {
-  SCM var =
+  SCM var;
+  scm_pthread_mutex_lock(&scm_i_define_mutex);
+  var =
     scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_T);
+  scm_i_pthread_mutex_unlock(&scm_i_define_mutex);
   SCM_VARIABLE_SET (var, value);
   return var;
 }
@@ -651,6 +656,8 @@ void
 scm_init_modules ()
 {
 #include "libguile/modules.x"
+  scm_i_pthread_mutex_init (&scm_i_define_mutex, NULL);
+
   module_make_local_var_x_var = scm_c_define ("module-make-local-var!",
 					    SCM_UNDEFINED);
   scm_tc16_eval_closure = scm_make_smob_type ("eval-closure", 0);


(file #17118)
    _______________________________________________________

Additional Item Attachment:

File name: define-race.patch              Size:1 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?24867>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





  reply	other threads:[~2008-12-23  2:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-18 10:18 [bug #24867] `define' should be thread-safe Ludovic Courtès
2008-11-18 13:27 ` Ludovic Courtès
2008-12-23  2:36   ` Linas Vepstas [this message]
2008-12-23  2:50     ` Linas Vepstas
2008-12-23  3:06       ` Linas Vepstas
2008-12-23 15:21         ` Ludovic Courtès
2008-12-23 18:28           ` Linas Vepstas
2008-12-23 19:10             ` Linas Vepstas
2010-09-20  9:28               ` Kourtney Keese
2011-08-06  9:08                 ` JackBenny
2011-08-06  9:08                   ` JackBenny
2011-08-06  9:09                     ` JackBenny
2011-08-06  9:09                       ` JackBenny

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=20081223-023612.sv71519.31021@savannah.gnu.org \
    --to=invalid.noreply@gnu.org \
    --cc=bug-guile@gnu.org \
    --cc=linasvepstas@gmail.com \
    --cc=ludo@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).