unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Han-Wen Nienhuys  <hanwen@xs4all.nl>
Cc: jantien@xs4all.nl
Subject: scm_gc_unprotect during GC
Date: Sat, 11 Sep 2004 03:23:42 +0200	[thread overview]
Message-ID: <16706.21406.130861.89431@byrd.xs4all.nl> (raw)


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


             reply	other threads:[~2004-09-11  1:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-11  1:23 Han-Wen Nienhuys [this message]
2004-09-21 21:23 ` scm_gc_unprotect during GC Marius Vollmer
2004-09-24  9:24   ` Han-Wen Nienhuys

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=16706.21406.130861.89431@byrd.xs4all.nl \
    --to=hanwen@xs4all.nl \
    --cc=jantien@xs4all.nl \
    /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).