From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: catching scm_without_guile badness Date: Thu, 31 Jul 2008 13:39:28 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1217504414 25158 80.91.229.12 (31 Jul 2008 11:40:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 31 Jul 2008 11:40:14 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Jul 31 13:41:03 2008 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 1KOWWg-0003jo-3t for guile-devel@m.gmane.org; Thu, 31 Jul 2008 13:40:58 +0200 Original-Received: from localhost ([127.0.0.1]:51012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KOWVl-0004fh-L2 for guile-devel@m.gmane.org; Thu, 31 Jul 2008 07:40:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KOWVc-0004dw-Dx for guile-devel@gnu.org; Thu, 31 Jul 2008 07:39:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KOWVX-0004ZA-LK for guile-devel@gnu.org; Thu, 31 Jul 2008 07:39:51 -0400 Original-Received: from [199.232.76.173] (port=51530 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KOWVX-0004Yi-C2 for guile-devel@gnu.org; Thu, 31 Jul 2008 07:39:47 -0400 Original-Received: from a-sasl-fastnet.sasl.smtp.pobox.com ([207.106.133.19]:53992 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KOWVX-000775-4T for guile-devel@gnu.org; Thu, 31 Jul 2008 07:39:47 -0400 Original-Received: from localhost.localdomain (localhost [127.0.0.1]) by a-sasl-fastnet.sasl.smtp.pobox.com (Postfix) with ESMTP id 9035845F92 for ; Thu, 31 Jul 2008 07:39:43 -0400 (EDT) Original-Received: from unquote (226.Red-83-36-163.dynamicIP.rima-tde.net [83.36.163.226]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-sasl-fastnet.sasl.smtp.pobox.com (Postfix) with ESMTPSA id F3C4C45F91 for ; Thu, 31 Jul 2008 07:39:42 -0400 (EDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-Pobox-Relay-ID: 5E76145C-5EF5-11DD-8F59-CE28B26B55AE-02397024!a-sasl-fastnet.pobox.com X-detected-kernel: by monty-python.gnu.org: Solaris 10 (beta) 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:7403 Archived-At: Hi, I just spent a couple days tracking down a bug in my code that was due to calling scm_without_guile when I wasn't actually in Guile. This exhibited itself as a deadlock at some point in the future when a scm_without_guile that was lower on the stack exited, it tried to take the heap lock when the first scm_without_guile had already, unnecessarily taken it. The solution of course is to not call scm_without_guile when you're not in guile. (My problem was actually that I had failed to call scm_with_guile when re-entering into some scheme code.) The following patch aborts if suspend() is called, but the thread was not in guile mode. Does it make sense to yall? I guess we should benchmark it, it's a pretty hot spot. Cheers, Andy diff --git a/libguile/threads.c b/libguile/threads.c index 609fc99..e0d7e74 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -383,6 +383,9 @@ suspend (void) { scm_i_thread *t = SCM_I_CURRENT_THREAD; + if (t->top) + abort (); + /* record top of stack for the GC */ t->top = SCM_STACK_PTR (&t); /* save registers. */ @@ -459,6 +462,7 @@ guilify_self_1 (SCM_STACKITEM *base) scm_i_pthread_setspecific (scm_i_thread_key, t); + t->top = NULL; scm_i_pthread_mutex_lock (&t->heap_mutex); scm_i_pthread_mutex_lock (&thread_admin_mutex); -- http://wingolog.org/