* src/threads/thread.cpp: Use a finalizer to remove dead threads.
[cacao.git] / src / threads / posix / thread-posix.cpp
index 820d7260ee470ec645ce03c82945bd3a3a9bae93..058a3bda94522821d1b4bd600e21c667137f17cb 100644 (file)
@@ -459,6 +459,7 @@ void threads_impl_thread_clear(threadobject *t)
        t->index = 0;
        t->flags = 0;
        t->state = 0;
+       t->is_in_active_list = false;
 
        t->tid = 0;
 
@@ -532,6 +533,11 @@ void threads_impl_thread_reuse(threadobject *t)
 #endif
 }
 
+void threads_impl_clear_heap_pointers(threadobject *t)
+{
+       t->object = 0;
+       t->flc_object = 0;
+}
 
 /* threads_impl_preinit ********************************************************
 
@@ -1059,7 +1065,8 @@ static void threads_suspend_self()
 #endif
 
        // Release the suspension mutex and wait till we are resumed.
-       thread->suspendcond->wait(thread->suspendmutex);
+       while (thread->suspend_reason != SUSPEND_REASON_NONE)
+               thread->suspendcond->wait(thread->suspendmutex);
 
 #if defined(ENABLE_GC_CACAO)
        // XXX This is propably not ok!
@@ -1079,7 +1086,7 @@ static void threads_suspend_self()
 
 /**
  * Suspend the passed thread. Execution of that thread stops until the thread
- * is explicitly resumend again.
+ * is explicitly resumed again.
  *
  * @param thread The thread to be suspended.
  * @param reason Reason for suspending the given thread.
@@ -1117,9 +1124,8 @@ bool threads_suspend_thread(threadobject *thread, int32_t reason)
                        os::abort_errno("threads_suspend_thread: pthread_kill failed");
 
                // Wait for the thread to acknowledge the suspension.
-               // XXX A possible optimization would be to not wait here, but you
-               //     better think this through twice before trying it!
-               thread->suspendcond->wait(thread->suspendmutex);
+               while (!thread->suspended)
+                       thread->suspendcond->wait(thread->suspendmutex);
        }
 
        return true;