Issue #4696 has been updated by Motohiro KOSAKI.

File 0001-new-deadlock-check.patch added

添????失???????????????????????????????
----------------------------------------
Bug #4696: thread.c#lock_func() ??? spurious wakeup unsafe
http://redmine.ruby-lang.org/issues/4696

Author: Motohiro KOSAKI
Status: Assigned
Priority: Low
Assignee: Motohiro KOSAKI
Category: core
Target version: 1.9.3
ruby -v: ruby 1.9.3dev (2011-05-13 trunk 31548) [x86_64-linux]


???????????????????????????????起票?????????
???? lock_func (ie Mutex.lock?????)??以??????????????????????????
???質??????????????????????????????????????

------------------------------------------------------------------------
static int
lock_func(rb_thread_t *th, mutex_t *mutex, int timeout_ms)
{
    for (;;) {
        if (!mutex->th) {
            mutex->th = th;
            break;
        }

        mutex->cond_waiting++;
        if (timeout_ms) {
            ret = native_cond_timedwait(&mutex->cond, &mutex->lock, &timeout);
            if (ret == ETIMEDOUT) {
                interrupted = 2;
                mutex->cond_waiting--;
                break;
            }
        }
        else {
            native_cond_wait(&mutex->cond, &mutex->lock);
        }
        mutex->cond_notified--;

        if (RUBY_VM_INTERRUPTED(th)) {
            interrupted = 1;
            break;
        }
    }
    return interrupted;
}

------------------------------------------------------------------------

以????????????????????????????

1) native_cond_wait() ??? spurious wakeup??起?????????????????誰??native_cond_signal()???
   ?????????????????????????????? cond_notified ??????????????????????????????
   ???????以???????????????????????????誤?????????

2) pthread_cond_timedwait()?????????????????????????pthread_cond_signal()???起????????????????
   *??????*????????????????????????????????????????????????????????????????????????????????
   ?????????????????ETIMEOUT???????????????????????????????????????????ETIMEOUT???????
   ???????????????????????復帰????ETIMEOUT???信?????????????? mutex->cond_waiting ????????????????????
   対????????????????????cond wait??????????????????predicate???????????? mutex->th ???
   RUBY_VM_INTERRUPTED ????????????????????????????????????????????????????ETIMEOUT???????????
   ??????????????????????????????????影?????????????????????

(1)??? deadlock check??????????????????害?????????????YARV?????????????????
mutex->cond_waiting ?????????????????????????????????????????????????????????????????????????
(2)???pthread_cond_timedwit???使??????????????? r31373 ???????????


?????大??????spurious wakeup?????????以?????native_cond_signal()????????????wakeup????????
?????????証????????????????????????cond_signal??????+1??????wakeup?????????????-1??????設?????
???????????????????????????????

???????????????????????????????????deadlock??設????????簡???????????????????????????????????
lock_func??????unlock???????????????????????????????簡??????????????????????????????
mutex->th???NULL?????????????????????????????????????????????????????????????????????

?????????????????????????????添???????????????????????修正??対?????????????????????????????
??????込??????????????????????????????????????????????????????????????対???????????????????????????
?????????????


???????軽??????????????????????????????????????????調??????????????以?????????????
 
???Linux
  pthread_cond_wait()???glibc??????spurious wakeup対???????????????????????????????????
  spurious wakeup??????????????linux thread ??????????????????????EINTR??復帰?????????????????
  ????????????????????? thread_pthread.c#native_cond_wait() ??????????????(r31482)???影?????????????
  pthread_cond_timedwait()??復帰???????????????????????????????glibc?????????????????
  ?????????????????????????????????復帰??????????????clock_gettime()????????????????????????
  ????????????????????????復帰???ETIMEOUT??差?????????????????追?????????????????????起?????
  ?????????????????

???NetBSD
  ??????????pthread_cond_timedwait()???ETIMEOUT?????????????????????????????????????????????????

???Mac
  ?????????????????????????????????????? cond_wait()???0???復帰???????????????????????
  ????????????????????????????




-- 
http://redmine.ruby-lang.org