[前][次][番号順一覧][スレッド一覧][生データ]

yarv-dev:975

From: sheepman <sheepman sheepman.sakura.ne.jp>
Date: Thu, 23 Feb 2006 23:26:59 +0900
Subject: [yarv-dev:975] Re: open> SizedQueue is too slow

こんばんは、sheepman です。

On Thu, 23 Feb 2006 22:27:16 +0900
sheepman <sheepman sheepman.sakura.ne.jp> wrote:


> 
> 良く見ると、Queue#pop のraiseの位置もおかしいですね。
> 

@waiting に同じスレッドが複数回 push されることを防ぐ
必要がありました。

$ svn diff thread.rb
Index: thread.rb
===================================================================
--- thread.rb   (revision 474)
+++ thread.rb   (working copy)
@@ -176,17 +176,19 @@
   # thread isn't suspended, and an exception is raised.
   #
   def pop(non_block=false)
-    raise ThreadError, "queue empty" if non_block
+    @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{
-        if @que.empty?
-          @waiting.push Thread.current
-          @mutex.unlock_and_stop
-          @mutex.lock
-        else
-          return @que.shift
-        end
+        return @que.shift unless @que.empty?
       }
+      Thread.pass
     end
   end

ところで、Queue が @waiting で待ちスレッドを管理する必要性は
無いような気がするんですが、こういうものなんでしょうか。

-- 
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