From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.devel Subject: Re: Locks and threads Date: Wed, 11 Feb 2009 23:05:19 +0000 Message-ID: <87iqngd174.fsf@arudy.ossau.uklinux.net> References: <87mycsd2rj.fsf@arudy.ossau.uklinux.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1234393566 14036 80.91.229.12 (11 Feb 2009 23:06:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Feb 2009 23:06:06 +0000 (UTC) To: Guile Development Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Feb 12 00:07:20 2009 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LXOAL-0001un-Un for guile-devel@m.gmane.org; Thu, 12 Feb 2009 00:06:50 +0100 Original-Received: from localhost ([127.0.0.1]:40642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LXO92-0002Rc-3U for guile-devel@m.gmane.org; Wed, 11 Feb 2009 18:05:28 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LXO8w-0002RU-Ld for guile-devel@gnu.org; Wed, 11 Feb 2009 18:05:22 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LXO8w-0002RH-6r for guile-devel@gnu.org; Wed, 11 Feb 2009 18:05:22 -0500 Original-Received: from [199.232.76.173] (port=47632 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LXO8w-0002RE-3J for guile-devel@gnu.org; Wed, 11 Feb 2009 18:05:22 -0500 Original-Received: from mail3.uklinux.net ([80.84.72.33]:53456) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LXO8v-00082a-Ke for guile-devel@gnu.org; Wed, 11 Feb 2009 18:05:21 -0500 Original-Received: from arudy (host86-157-180-39.range86-157.btcentralplus.com [86.157.180.39]) by mail3.uklinux.net (Postfix) with ESMTP id E26F01F6B37 for ; Wed, 11 Feb 2009 23:05:20 +0000 (GMT) Original-Received: from arudy.ossau.uklinux.net (arudy [127.0.0.1]) by arudy (Postfix) with ESMTP id 79F0538012 for ; Wed, 11 Feb 2009 23:05:19 +0000 (GMT) In-Reply-To: <87mycsd2rj.fsf@arudy.ossau.uklinux.net> (Neil Jerram's message of "Wed\, 11 Feb 2009 22\:31\:28 +0000") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:8151 Archived-At: --=-=-= Neil Jerram writes: > - first to address problems reported by helgrind (since I think we > should take advantage of external tools before adding debug code to > Guile internally) Here's the next one. Neil --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Don-t-leave-Guile-mode-to-lock-async_mutex.patch >From 76f55c5796f1fc7aca6c36bc57f06bab72300a94 Mon Sep 17 00:00:00 2001 From: Neil Jerram Date: Wed, 11 Feb 2009 23:03:16 +0000 Subject: [PATCH] Don't leave Guile mode to lock async_mutex This fixes lots of helgrind-reported problems, such as: Thread #1: lock order "0x4325084 before 0x4108928" violated at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408) by 0x40CFD37: scm_enter_guile (threads.c:377) by 0x40D0284: scm_pthread_mutex_lock (threads.c:1485) by 0x405A736: scm_async_click (async.c:155) by 0x406F9EE: deval (eval.c:4080) by 0x40761D9: scm_primitive_eval_x (eval.c:5921) by 0x40AD20E: install_handler (scmsigs.c:113) by 0x40AD402: scm_sigaction_for_thread (scmsigs.c:394) by 0x4087D1F: scm_gsubr_apply (gsubr.c:223) by 0x406DF55: scm_dapply (eval.c:4930) by 0x407147C: deval (eval.c:4378) by 0x406E1BD: scm_dapply (eval.c:5012) Required order was established by acquisition of lock at 0x4325084 at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408) by 0x40CFD37: scm_enter_guile (threads.c:377) by 0x408C58B: scm_i_init_guile (init.c:421) by 0x40D1873: scm_i_init_thread_for_guile (threads.c:589) by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:731) by 0x40D19BD: scm_with_guile (threads.c:720) by 0x408C42E: scm_boot_guile (init.c:350) by 0x8048710: main (guile.c:69) followed by a later acquisition of lock at 0x4108928 at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408) by 0x40AFD61: scm_make_smob_type (smob.c:294) by 0x40AFF19: scm_smob_prehistory (smob.c:512) by 0x408C595: scm_i_init_guile (init.c:423) by 0x40D1873: scm_i_init_thread_for_guile (threads.c:589) by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:731) by 0x40D19BD: scm_with_guile (threads.c:720) by 0x408C42E: scm_boot_guile (init.c:350) by 0x8048710: main (guile.c:69) * libguile/async.c (scm_async_click): Don't leave Guile mode when locking async_mutex. We don't need to, because none of the code that has async_mutex locked can block, and doing so may lead to lock ordering problems between async_mutex and a thread's heap_mutex. --- libguile/async.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libguile/async.c b/libguile/async.c index a9763da..56634d5 100644 --- a/libguile/async.c +++ b/libguile/async.c @@ -152,7 +152,7 @@ scm_async_click () invoked even when pending_asyncs is zero. */ - scm_i_scm_pthread_mutex_lock (&async_mutex); + scm_i_pthread_mutex_lock (&async_mutex); t->pending_asyncs = 0; if (t->block_asyncs == 0) { @@ -197,7 +197,7 @@ scm_i_queue_async_cell (SCM c, scm_i_thread *t) int sleep_fd; SCM p; - scm_i_scm_pthread_mutex_lock (&async_mutex); + scm_i_pthread_mutex_lock (&async_mutex); p = t->active_asyncs; SCM_SETCDR (c, SCM_EOL); if (!scm_is_pair (p)) @@ -263,7 +263,7 @@ scm_i_setup_sleep (scm_i_thread *t, { int pending; - scm_i_scm_pthread_mutex_lock (&async_mutex); + scm_i_pthread_mutex_lock (&async_mutex); pending = t->pending_asyncs; if (!pending) { @@ -278,7 +278,7 @@ scm_i_setup_sleep (scm_i_thread *t, void scm_i_reset_sleep (scm_i_thread *t) { - scm_i_scm_pthread_mutex_lock (&async_mutex); + scm_i_pthread_mutex_lock (&async_mutex); t->sleep_object = SCM_BOOL_F; t->sleep_mutex = NULL; t->sleep_fd = -1; -- 1.5.6.5 --=-=-=--