Revision
4402
Author
lsansonetti@apple.com
Date
2010-08-03 12:45:51 -0700 (Tue, 03 Aug 2010)

Log Message

when unregistering a thread, mark is as dead very early to avoid pthread mutex lock problems when potentially cancelling it later (fixes #794, patch by watson1978 at gmail.com)

Modified Paths

Diff

Modified: MacRuby/trunk/vm.cpp (4401 => 4402)


--- MacRuby/trunk/vm.cpp	2010-08-03 06:36:29 UTC (rev 4401)
+++ MacRuby/trunk/vm.cpp	2010-08-03 19:45:51 UTC (rev 4402)
@@ -4291,6 +4291,9 @@
 {
     RoxorCoreLock lock;
 
+    rb_vm_thread_t *t = GetThreadPtr(thread);
+    t->status = THREAD_DEAD;
+
     // We do not call #delete because it might trigger #== in case it has been
     // overriden on the thread object, and therefore cause a deadlock if the
     // new method tries to acquire the RoxorCore GIL.
@@ -4311,8 +4314,6 @@
 
     lock.unlock();
 
-    rb_vm_thread_t *t = GetThreadPtr(thread);
-
     const int code = pthread_mutex_destroy(&t->sleep_mutex);
     if (code == EBUSY) {
 	// The mutex is already locked, which means we are being called from
@@ -4333,8 +4334,6 @@
     t->vm = NULL;
 
     pthread_assert(pthread_setspecific(RoxorVM::vm_thread_key, NULL));
-
-    t->status = THREAD_DEAD;
 }
 
 static inline void