[MacRuby-devel] [MacRuby] #794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22)

MacRuby ruby-noreply at macosforge.org
Tue Aug 3 09:02:28 PDT 2010


#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22)
----------------------------------+-----------------------------------------
 Reporter:  watson1978@…          |       Owner:  lsansonetti@…        
     Type:  defect                |      Status:  new                  
 Priority:  blocker               |   Milestone:                       
Component:  MacRuby               |    Keywords:                       
----------------------------------+-----------------------------------------

Comment(by watson1978@…):

 It is necessary for "t->status = THREAD_DEAD" to move to the top of
 RoxorCore::unregister_thread().[[BR]]
 The reason is because it becomes the error when pthread_mutex_lock() in
 rb_vm_thread_cancel() is executed between pthread_mutex_destroy() and
 "t->status = THREAD_DEAD".

 {{{
 #!diff
 diff --git a/vm.cpp b/vm.cpp
 index 60e6db4..1f6dc86 100644
 --- a/vm.cpp
 +++ b/vm.cpp
 @@ -4291,6 +4291,9 @@ RoxorCore::unregister_thread(VALUE thread)
  {
      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 @@ RoxorCore::unregister_thread(VALUE thread)

      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 @@ RoxorCore::unregister_thread(VALUE thread)
      t->vm = NULL;

      pthread_assert(pthread_setspecific(RoxorVM::vm_thread_key, NULL));
 -
 -    t->status = THREAD_DEAD;
  }

  static inline void
 }}}

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:6>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list