Project

General

Profile

Actions

Backport #5155

closed

[BUG] pthread_cond_signal: Resource temporarily unavailable (EAGAIN)

Added by mrkn (Kenta Murata) over 12 years ago. Updated almost 8 years ago.

Status:
Rejected
[ruby-dev:44342]

Description

1.9.2p290 に http://d.hatena.ne.jp/mrkn/20110728/use_ruby_1_9_2_on_lion で公開したパッチを当て、
gcc-4.2 を使ってビルドした ruby を使用しています。

長い時間起動しっぱなしにしてあるプロセスが何らかのタイミングで以下のメッセージを吐いて止まります。
[BUG] pthread_cond_signal: Resource temporarily unavailable (EAGAIN)

止まる原因は、プロセスが長時間 (だいたい1日以上) ブロックされ続けた後、入力やシグナルを受け取って再度動き始めるタイミングです。
まだ何も調査してませんが、一応報告しておきます。

trunk で起きるかどうかも、まだ調べておりません。


Related issues 1 (0 open1 closed)

Has duplicate Backport192 - Backport #5205: Long-running Ruby process hit EAGAIN in Ruby 1.9.2 as it attempted to terminateRejectedyugui (Yuki Sonoda)Actions

Updated by mrkn (Kenta Murata) over 12 years ago

補足ですが、私のブログで公開しているパッチは、
#5074 でバックポート要請されているコミット (関数の引き数に volatile を付ける) をバックポートし、
コンパイラを gcc-4.2 を優先して使うようにするパッチを configure.in に当てているだけです。

ですから、ほとんど 1.9.2p290 と同じものだと考えて良いと思います。

Updated by kosaki (Motohiro KOSAKI) over 12 years ago

Snow Leopardのpthread_cond_signal()にはEAGAINを返すルートがないようなんですが、Lionから1つ出来てますね。


int
pthread_cond_signal_thread_np(pthread_cond_t ocond, pthread_t thread)
{
(snip)
if (((thread == 0) && (is_seqhigher((ucntval & PTHRW_COUNT_MASK), (lcntval & PTHRW_COUNT_MASK)))) || is_seqhigher((scntval & PTHRW_COUNT_MASK), (lcntval & PTHRW_COUNT_MASK))) {
/
since ucntval may be newer, just redo */
retry_count++;
if (retry_count > 8192) {
return(EAGAIN);
} else {
sched_yield();
goto retry;
}
}


8000回リトライしたら諦めてEAGAINという驚愕のコードに見えるので、たんにEAGAIN帰ってきたらもう一回 pthread_cond_signal()
するのがよさそう。リトライするときにusleep()するかどうかぐらいが悩みどころか

Updated by naruse (Yui NARUSE) over 12 years ago

man ちゃんと更新しとけと Apple に Problem ID: 9894106 として報告しておきました。

Summary:
On Mac OS X 10.7 Lion, pthread_cond_signal(3) may return EAGAIN but man doesn't describe it.

Steps to Reproduce:
See pthread_cond_signal_thread_np of
http://www.opensource.apple.com/source/Libc/Libc-763.11/pthreads/pthread_cond.c
It is called by pthread_cond_signal and may returns EAGAIN.
But man http://www.opensource.apple.com/source/Libc/Libc-763.11/pthreads/pthread_cond_signal.3
doesn't describe it.
Note that Snow Leopard doesn't return EAGAIN.

Updated by mrkn (Kenta Murata) over 12 years ago

https://gist.github.com/1124278

このようなパッチで如何でしょう?

Updated by kosaki (Motohiro KOSAKI) over 12 years ago

このようなパッチで如何でしょう?

僕的にはOKです

Updated by mrkn (Kenta Murata) over 12 years ago

trunk と ruby_1_9_3 ブランチに取り込みます。
その後、このチケットを 1.9.2 向けの Backport に移行させます。

Actions #7

Updated by mrkn (Kenta Murata) over 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32846.
Kenta, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • thread_pthread.c (native_cond_signal): retry to call pthread_cond_signal
    and pthread_cond_broadcast if they return EAGAIN in
    native_cond_signal and native_cond_broadcast, respectively.
    It is for the pthread implementation of Mac OS X 10.7 (Lion).
    fixes #5155. [ruby-dev:44342].
  • thread_pthread.c (native_cond_broadcast): ditto.
  • thread_pthread.c (struct cached_thread_entry): stop using
    pthread_cond_t and its functions directly.
  • thread_pthread.c (register_cached_thread_and_wait): ditto.
  • thread_pthread.c (use_cached_thread): ditto.
Actions #8

Updated by mrkn (Kenta Murata) over 12 years ago

  • Tracker changed from Bug to Backport
  • Status changed from Closed to Assigned
  • Assignee set to yugui (Yuki Sonoda)

1.9.2 へのバックポートも必要です。1.9.2 向けのパッチは gist に置きました。
https://gist.github.com/1124278

Actions #9

Updated by naruse (Yui NARUSE) over 12 years ago

  • Project changed from Ruby master to Backport192
  • Category changed from core to core
  • Target version deleted (1.9.2)
  • Parent task deleted (#5076)
Actions #10

Updated by naruse (Yui NARUSE) almost 8 years ago

  • Status changed from Assigned to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0