[#44289] [Ruby 1.9 - Feature #5128][Open] 日本語ドキュメントをUTF-8に — Shyouhei Urabe <shyouhei@...>

34 messages 2011/08/01
[#44293] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Nobuyoshi Nakada <nobu@...> 2011/08/01

[#44295] Re: [ruby-dev:44293] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Urabe Shyouhei <shyouhei@...> 2011/08/01

(08/01/2011 11:52 AM), Nobuyoshi Nakada wrote:

[#44299] Re: [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Nobuyoshi Nakada <nobu@...> 2011/08/01

なかだです。

[#44418] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Ayumu AIZAWA <ayumu.aizawa@...> 2011/08/24

[#44431] Re: [ruby-dev:44418] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — KOSAKI Motohiro <kosaki.motohiro@...> 2011/08/27

> あいざわです

[#44443] Re: [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Ayumu Aizawa <ayumu.aizawa@...> 2011/09/01

あいざわです

[#44315] [Ruby 1.9 - Bug #5139][Open] sigsegv のスタックオーバフロー — Tomoyuki Chikanaga <nagachika00@...>

18 messages 2011/08/02

[#44329] [Ruby 1.9 - Bug #5151][Open] test/socket/test_socket.rb fail when udp connection failed — Ayumu AIZAWA <ayumu.aizawa@...>

16 messages 2011/08/02

[#44368] [Ruby 1.9 - Feature #5180][Open] net/http の接続時に用いる IP アドレスの指定 — Yui NARUSE <naruse@...>

15 messages 2011/08/10

[#44413] [Ruby 1.9 - Bug #5217][Open] lineno is broken when source code has about 7000 lines — Yusuke Endoh <mame@...>

11 messages 2011/08/23

[ruby-dev:44400] [Ruby 1.9 - Bug #5195][Open] Queue#popでsleepしているthreadをwakeupさせるとQueueの@waitingにそのthreadがpushされてしまう

From: Masaki Matsushita <glass.saga@...>
Date: 2011-08-16 13:19:06 UTC
List: ruby-dev #44400
Issue #5195 has been reported by Masaki Matsushita.

----------------------------------------
Bug #5195: Queue#popでsleepしているthreadをwakeupさせるとQueueの@waitingにそのthreadがpushされてしまう
http://redmine.ruby-lang.org/issues/5195

Author: Masaki Matsushita
Status: Open
Priority: Normal
Assignee: 
Category: lib
Target version: 1.9.x
ruby -v: ruby 1.9.4dev (2011-08-14 trunk 32972) [x86_64-linux]


=begin
次のようなコードを実行すると、
 
 require 'thread'
 
 queue = Queue.new
 
 t1 = Thread.start { queue.pop; p 1 }
 
 nil until t1.stop?
 t1.wakeup
 nil until t1.stop?
 
 t2 = Thread.start { queue.pop; p 2 }
 
 nil until t1.stop? && t2.stop?
 
 p t1, t2
 queue.instance_eval{ p @waiting }
 
 2.times{ queue.push(nil) }
 
 t1.join
 t2.join

以下のような結果となります。

 #<Thread:0x000000014d8108 sleep>
 #<Thread:0x000000014d8090 sleep>
 [#<Thread:0x000000014d8108 sleep>, #<Thread:0x000000014d8108 sleep>, #<Thread:0x000000014d8090 sleep>]
 1
 /home/masaki/ruby/queue_waiting.rb:22:in `join': deadlock detected (fatal)
 from /home/masaki/ruby/queue_waiting.rb:22:in `<main>'

lib/thread.rbの184行目でQueue#popが以下のように定義されていますが、

 def pop(non_block=false)
    @mutex.synchronize{
      while true
        if @que.empty?
          raise ThreadError, "queue empty" if non_block
          @waiting.push Thread.current
          @mutex.sleep
        else
          return @que.shift
        end
      end
    }
  end

このコードではQueue#popでsleepしているthreadをwakeupさせると、既にpush済みのThread.currentが再度@waitingにpushされてしまいます。
これはバグではないでしょうか。

patchを添付します。
このpatchでは遅くなってしまうのではないかと懸念しましたが、

 require 'benchmark'
 require 'thread'
 
 def push_pop
   q = Queue.new
   time = 100000
 
   push = Thread.start do
     time.times { q.push(nil) }
   end
 
   pop = Thread.start do
     time.times { q.pop }
   end
 
   push.join
   pop.join
 end
 
 Benchmark.bm do |x|
   x.report("before") { push_pop }
 end

というベンチマークを作って試してみたところ、
patchの適用以前が

 user     system      total        real
 0.460000   0.000000   0.460000 (  0.452595)
 0.500000   0.040000   0.540000 (  0.529834)
 0.410000   0.030000   0.440000 (  0.433928)

適用後が

 user     system      total        real
 0.480000   0.060000   0.540000 (  0.505939)
 0.450000   0.000000   0.450000 (  0.449451)
 0.430000   0.010000   0.440000 (  0.435586)

となったのでそれほどには遅くなっていないようです。
patchの適用後もtest/thread/test_queue.rbをパスします。

=end


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

In This Thread

Prev Next