]> git.eshelyaron.com Git - emacs.git/commitdiff
fix a few latent issues in the thread patch
authorTom Tromey <tromey@redhat.com>
Thu, 6 Jun 2013 19:18:05 +0000 (13:18 -0600)
committerTom Tromey <tromey@redhat.com>
Thu, 6 Jun 2013 19:18:05 +0000 (13:18 -0600)
* we called unbind_for_thread_switch unconditionally, but this
  is wrong if the previous thread exited
* likewise, exiting a thread should clear current_thread
* redundant assignment in run_thread
* clean up init_threads - no need to re-init the primary thread

This patch still sometimes causes weird hangs in "make check".
However, I think that is a kernel bug, since Emacs enters the zombie
state but its parent process hangs in wait.  This shouldn't happen.

src/thread.c

index 1d282c3557ac25dc45c8c2d076e11bb7c2678acb..8f58faf1b089316857c0f0b4c38e5646411e2dd0 100644 (file)
@@ -52,7 +52,11 @@ post_acquire_global_lock (struct thread_state *self)
 
   if (self != current_thread)
     {
-      unbind_for_thread_switch ();
+      /* CURRENT_THREAD is NULL if the previously current thread
+        exited.  In this case, there is no reason to unbind, and
+        trying will crash.  */
+      if (current_thread != NULL)
+       unbind_for_thread_switch ();
       current_thread = self;
       rebind_for_thread_switch ();
     }
@@ -625,7 +629,7 @@ run_thread (void *state)
   struct thread_state **iter;
 
   self->m_stack_bottom = &stack_pos;
-  self->stack_top = self->m_stack_bottom = &stack_pos;
+  self->stack_top = &stack_pos;
   self->thread_id = sys_thread_self ();
 
   acquire_global_lock (self);
@@ -653,6 +657,7 @@ run_thread (void *state)
   self->m_specpdl_ptr = NULL;
   self->m_specpdl_size = 0;
 
+  current_thread = NULL;
   sys_cond_broadcast (&self->thread_condvar);
 
   release_global_lock ();
@@ -905,8 +910,6 @@ init_primary_thread (void)
   primary_thread.error_symbol = Qnil;
   primary_thread.error_data = Qnil;
   primary_thread.event_object = Qnil;
-
-  sys_cond_init (&primary_thread.thread_condvar);
 }
 
 void
@@ -918,10 +921,11 @@ init_threads_once (void)
 void
 init_threads (void)
 {
-  init_primary_thread ();
-
+  sys_cond_init (&primary_thread.thread_condvar);
   sys_mutex_init (&global_lock);
   sys_mutex_lock (&global_lock);
+  current_thread = &primary_thread;
+  primary_thread.thread_id = sys_thread_self ();
 }
 
 void