From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Han-Wen Nienhuys Newsgroups: gmane.lisp.guile.devel Subject: scm_gc_unprotect during GC Date: Sat, 11 Sep 2004 03:23:42 +0200 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <16706.21406.130861.89431@byrd.xs4all.nl> Reply-To: hanwen@xs4all.nl NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1094865841 19640 80.91.224.253 (11 Sep 2004 01:24:01 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 11 Sep 2004 01:24:01 +0000 (UTC) Cc: jantien@xs4all.nl Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Sep 11 03:23:48 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C5wcG-0003KL-00 for ; Sat, 11 Sep 2004 03:23:48 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C5whf-0005k3-0p for guile-devel@m.gmane.org; Fri, 10 Sep 2004 21:29:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C5whX-0005jo-Ko for guile-devel@gnu.org; Fri, 10 Sep 2004 21:29:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C5whW-0005jc-3H for guile-devel@gnu.org; Fri, 10 Sep 2004 21:29:15 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C5whV-0005jZ-Vw for guile-devel@gnu.org; Fri, 10 Sep 2004 21:29:14 -0400 Original-Received: from [213.84.26.127] (helo=byrd.xs4all.nl) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1C5wc1-0000Yv-Ow for guile-devel@gnu.org; Fri, 10 Sep 2004 21:23:34 -0400 Original-Received: from byrd.xs4all.nl.byrd.xs4all.nl (byrd [127.0.0.1]) by byrd.xs4all.nl (8.13.0/8.13.0) with ESMTP id i8B1NgDK012164; Sat, 11 Sep 2004 03:23:42 +0200 Original-To: guile-devel@gnu.org, mvo@zagadka.de X-Mailer: VM 7.14 under Emacs 21.3.1 X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner: Found to be clean X-MailScanner-From: hanwen@xs4all.nl 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: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:4117 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4117 Investigations in the signal 6 problem that I reported recently, pointed me to a call of scm_gc_unprotect_object, which does SCM_REDEFER_INTS and SCM_ALLOW_INTS The last call sets SCM_CURRENT_THREAD->top to NULL, which triggers an assertion failure later on in scm_threads_mark_stacks. A short term solution is to make sure that LilyPond never does scm_gc_unprotect_object() from smobbed destructor. However, I feel that this is a kludge. Either scm_gc_unprotect_object is callable during sweep, or this is forbidden. At present, GUILE does not print a warning, but barfs in an unrelated location. I vote that scm_gc_unprotect_object() should be callable. I assume that the proper solution would be to check whether the current thread is already suspended. A patch is below; it also catches wrongly balanced resume and suspend calls. Unfortunately, make check barfs, due to the thread marker marking a NULL location during unif.test - I haven't figured out how to run the tests in isolation, so I stop here. As I am very unfamiliar with multi-threaded coding, I would appreciate comments whether this is a viable approach --- threads.c.~1.66.~ 2004-09-04 02:02:31.000000000 +0200 +++ threads.c 2004-09-11 03:15:17.138205672 +0200 @@ -116,7 +116,8 @@ scm_t_thread thread; SCM result; int exited; - + int suspend_count; + /* For keeping track of the stack and registers. */ SCM_STACKITEM *base; SCM_STACKITEM *top; @@ -134,6 +135,11 @@ t->handle = z; t->result = creation_protects; t->base = NULL; + + /* + threads are suspended on creation. + */ + t->suspend_count = 1; scm_i_plugin_cond_init (&t->sleep_cond, 0); scm_i_plugin_mutex_init (&t->heap_mutex, &scm_i_plugin_mutex); t->clear_freelists_p = 0; @@ -194,16 +200,25 @@ scm_setspecific (scm_i_root_state_key, data); t->root = (scm_root_state *)data; } - +#define SUSPENDCOUNT static void resume (scm_thread *t) { - t->top = NULL; - if (t->clear_freelists_p) +#ifdef SUSPENDCOUNT + t->suspend_count--; + + assert(t->suspend_count >= 0); + + if (t->suspend_count == 0) +#endif { - *SCM_FREELIST_LOC (scm_i_freelist) = SCM_EOL; - *SCM_FREELIST_LOC (scm_i_freelist2) = SCM_EOL; - t->clear_freelists_p = 0; + t->top = NULL; + if (t->clear_freelists_p) + { + *SCM_FREELIST_LOC (scm_i_freelist) = SCM_EOL; + *SCM_FREELIST_LOC (scm_i_freelist2) = SCM_EOL; + t->clear_freelists_p = 0; + } } } @@ -219,12 +234,19 @@ { scm_thread *c = SCM_CURRENT_THREAD; - /* record top of stack for the GC */ - c->top = SCM_STACK_PTR (&c); - /* save registers. */ - SCM_FLUSH_REGISTER_WINDOWS; - setjmp (c->regs); +#ifdef SUSPENDCOUNT + if (c->suspend_count == 0) +#endif + { + /* record top of stack for the GC */ + c->top = SCM_STACK_PTR (&c); + /* save registers. */ + SCM_FLUSH_REGISTER_WINDOWS; + setjmp (c->regs); + + } + c->suspend_count ++; return c; } @@ -947,7 +969,7 @@ continue; } - if (t->top == NULL) + if (t->suspend_count == 0) // (t->top == NULL) { /* Thread has not been suspended, which should never happen. */ @@ -1241,6 +1263,7 @@ /* Allocate a fake thread object to be used during bootup. */ t = malloc (sizeof (scm_thread)); t->base = NULL; + t->suspend_count = 1; t->clear_freelists_p = 0; scm_i_plugin_mutex_init (&t->heap_mutex, &scm_i_plugin_mutex); scm_setspecific (scm_i_thread_key, t); -- Han-Wen Nienhuys | hanwen@xs4all.nl | http://www.xs4all.nl/~hanwen _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel