unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Locks and threads
@ 2009-02-11 22:31 Neil Jerram
  2009-02-11 23:05 ` Neil Jerram
                   ` (4 more replies)
  0 siblings, 5 replies; 51+ messages in thread
From: Neil Jerram @ 2009-02-11 22:31 UTC (permalink / raw)
  To: Guile Development; +Cc: Linas Vepstas

[-- Attachment #1: Type: text/plain, Size: 727 bytes --]

I've started working through the lock ordering and threading issues
that we have.  My plan is (with 1.8.x)

- first to address problems reported by helgrind (since I think we
  should take advantage of external tools before adding debug code to
  Guile internally)

- then to run Linas's define-race program, and address the problems
  that that shows up (including thread-safe define, hopefully)

- then (or maybe as part of the previous step) to look again at
  Linas's lock order debugging patch, to see if it would make sense to
  apply some of that.

Does that sound sensible; have I missed anything?

A patch for the first helgrind problem is attached; any comments would
be appreciated, as ever.

Regards,
        Neil


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Lock-ordering-don-t-lock-heap_mutex-and-then-thread.patch --]
[-- Type: text/x-diff, Size: 2882 bytes --]

From 3dcf473e9e535314fc6dedc99ff8d9132e7a3e3e Mon Sep 17 00:00:00 2001
From: Neil Jerram <neil@ossau.uklinux.net>
Date: Wed, 11 Feb 2009 21:22:57 +0000
Subject: [PATCH] Lock ordering: don't lock heap_mutex and then thread_admin_mutex

This fixes the following helgrind report.

Thread #1: lock order "0x4325084 before 0x4105328" violated
   at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
   by 0x40D01EA: scm_i_thread_put_to_sleep (threads.c:1622)
   by 0x4078958: scm_make_fluid (fluids.c:114)
   by 0x40778D6: scm_init_feature (feature.c:101)
   by 0x408C62E: scm_i_init_guile (init.c:464)
   by 0x40D1873: scm_i_init_thread_for_guile (threads.c:583)
   by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:725)
   by 0x40D19BD: scm_with_guile (threads.c:714)
   by 0x408C42E: scm_boot_guile (init.c:350)
   by 0x8048710: main (guile.c:69)
  Required order was established by acquisition of lock at 0x4325084
   at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
   by 0x40CFFA4: guilify_self_1 (threads.c:468)
   by 0x408C58B: scm_i_init_guile (init.c:421)
   by 0x40D1873: scm_i_init_thread_for_guile (threads.c:583)
   by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:725)
   by 0x40D19BD: scm_with_guile (threads.c:714)
   by 0x408C42E: scm_boot_guile (init.c:350)
   by 0x8048710: main (guile.c:69)
  followed by a later acquisition of lock at 0x4105328
   at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
   by 0x40CFFAC: guilify_self_1 (threads.c:470)
   by 0x408C58B: scm_i_init_guile (init.c:421)
   by 0x40D1873: scm_i_init_thread_for_guile (threads.c:583)
   by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:725)
   by 0x40D19BD: scm_with_guile (threads.c:714)
   by 0x408C42E: scm_boot_guile (init.c:350)
   by 0x8048710: main (guile.c:69)

* threads.c (guilify_self_1): Add self to global thread list _before_
  entering Guile mode.
---
 libguile/threads.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libguile/threads.c b/libguile/threads.c
index ba17746..05e01e3 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -465,13 +465,19 @@ guilify_self_1 (SCM_STACKITEM *base)
 
   scm_i_pthread_setspecific (scm_i_thread_key, t);
 
-  scm_i_pthread_mutex_lock (&t->heap_mutex);
-
+  /* As soon as this thread adds itself to the global thread list, the
+     GC may think that it has a stack that needs marking.  Therefore
+     initialize t->top to be the same as t->base, just in case GC runs
+     before the thread can lock its heap_mutex for the first time. */
+  t->top = t->base;
   scm_i_pthread_mutex_lock (&thread_admin_mutex);
   t->next_thread = all_threads;
   all_threads = t;
   thread_count++;
   scm_i_pthread_mutex_unlock (&thread_admin_mutex);
+
+  /* Enter Guile mode. */
+  scm_enter_guile (t);
 }
 
 /* Perform second stage of thread initialisation, in guile mode.
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2009-03-27  3:15 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-11 22:31 Locks and threads Neil Jerram
2009-02-11 23:05 ` Neil Jerram
2009-02-11 23:32   ` Ludovic Courtès
2009-02-11 23:30 ` Linas Vepstas
2009-02-11 23:53   ` Neil Jerram
2009-02-12  0:18     ` Linas Vepstas
2009-02-12 20:51     ` Ludovic Courtès
2009-02-11 23:30 ` Ludovic Courtès
2009-02-12 12:55 ` Greg Troxel
2009-02-12 18:00   ` Ken Raeburn
2009-02-12 21:14     ` Ludovic Courtès
2009-02-14  1:25       ` Ken Raeburn
2009-02-14 16:09         ` Ludovic Courtès
2009-03-05 20:41   ` Neil Jerram
2009-03-04 23:49 ` Neil Jerram
2009-03-05  3:54   ` Linas Vepstas
2009-03-05 19:46     ` Neil Jerram
2009-03-05 20:05       ` Neil Jerram
2009-03-05 20:40         ` Linas Vepstas
2009-03-05 20:49           ` Neil Jerram
2009-03-05 20:57         ` Linas Vepstas
2009-03-05 21:25           ` Neil Jerram
2009-03-05 21:56             ` Linas Vepstas
2009-03-06 11:01               ` Andy Wingo
2009-03-06 12:36                 ` Linas Vepstas
2009-03-06 22:05                   ` Ludovic Courtès
2009-03-08 22:04               ` Neil Jerram
2009-03-25 19:00         ` Neil Jerram
2009-03-25 22:08           ` Ludovic Courtès
2009-03-05 21:35   ` Ludovic Courtès
2009-03-10 23:57   ` Neil Jerram
2009-03-12  0:07     ` Neil Jerram
2009-03-12  0:53       ` Neil Jerram
2009-03-12  1:29         ` Linas Vepstas
2009-03-12  3:09           ` Clinton Ebadi
2009-03-25 22:13           ` Neil Jerram
2009-03-25 22:34             ` Linas Vepstas
2009-03-12 22:13         ` Andy Wingo
2009-03-13 19:13           ` Neil Jerram
2009-03-25 23:19             ` Neil Jerram
2009-03-26  3:40               ` Linas Vepstas
2009-03-26  8:02                 ` Neil Jerram
2009-03-26 18:39                   ` Linas Vepstas
2009-03-26  9:10               ` Ludovic Courtès
2009-03-26 22:01                 ` Neil Jerram
2009-03-26 23:12                   ` Ludovic Courtès
2009-03-26 22:51               ` Neil Jerram
2009-03-27  3:15                 ` Linas Vepstas
2009-03-14 14:23           ` Ludovic Courtès
2009-03-16 22:57             ` Andy Wingo
2009-03-25 18:57     ` Neil Jerram

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).