yarv-dev:990
From: sheepman <sheepman sheepman.sakura.ne.jp>
Date: Mon, 27 Feb 2006 22:07:33 +0900
Subject: [yarv-dev:990] Re: fixed> Re: SizedQueue is too slow
こんばんは、sheepman です。 On Mon, 27 Feb 2006 11:42:18 +0900 (JST) Minero Aoki <aamine loveruby.net> wrote: > > > > 良く見ると、Queue#pop のraiseの位置もおかしいですね。 > > > @waiting に同じスレッドが複数回 push されることを防ぐ > > 必要がありました。 > > ありがとうございます。とりあえずあてておきました。 > すいません、今のコードだとビジーループになってしまいます。 元のコードに revert して下さい。お手数ですがお願いします。 $ svn diff thread.rb Index: thread.rb =================================================================== --- thread.rb (revision 479) +++ thread.rb (working copy) @@ -176,19 +176,18 @@ # thread isn't suspended, and an exception is raised. # def pop(non_block=false) - @mutex.synchronize{ - if @que.empty? - raise ThreadError, "queue empty" if non_block - @waiting.push Thread.current - else - return @que.shift - end - } while true @mutex.synchronize{ - return @que.shift unless @que.empty? + if @que.empty? + raise ThreadError, "queue empty" if non_block + @waiting.push Thread.current + @mutex.unlock_and_stop + @mutex.lock + break + else + return @que.shift + end } - Thread.pass end end > > ところで、Queue が @waiting で待ちスレッドを管理する必要性は > > 無いような気がするんですが、こういうものなんでしょうか。 > > 元からあったコードなので、書いた人に聞かないとなんとも……。 > 質問した時には良く分かってなかったんですが、ConditionalVariable相当が ネイティブスレッドライブラリを使って実装されていない現状では必要なんだと思います。 -- sheepman / TAMURA Takashi sheepman sheepman.sakura.ne.jp http://sheepman.parfait.ne.jp/ -- ML: yarv-dev quickml.atdot.net 使い方: http://www.atdot.net/~ko1/quickml
973 2006-02-23 22:15 [sheepman sheepman.sa] open> SizedQueue is too slow 974 2006-02-23 22:27 ┗[sheepman sheepman.sa] 975 2006-02-23 23:26 ┗[sheepman sheepman.sa] 983 2006-02-27 11:42 ┗[aamine loveruby.net ] fixed> Re: SizedQueue is too slow 984 2006-02-27 15:21 ┣[matz ruby-lang.org ] -> 990 2006-02-27 22:07 ┗[sheepman sheepman.sa] 991 2006-02-27 22:09 ┣[ko1 atdot.net ] 993 2006-02-27 22:41 ┗[aamine loveruby.net ] Re: SizedQueue is too slow