Project

General

Profile

Actions

Bug #293

closed

context switch may occur during freeing io

Added by mame (Yusuke Endoh) almost 16 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
Backport:
[ruby-dev:35578]

Description

=begin
遠藤です。

以下のように do_select の blocking region に native_thread_yield を
入れた上で、

Index: thread.c

--- thread.c (revision 18124)
+++ thread.c (working copy)
@@ -2004,6 +2004,7 @@
}
#else
BLOCKING_REGION({

  • native_thread_yield();
    result = select(n, read, write, except, timeout);
    if (result < 0) lerrno = errno;
    }, ubf_select, GET_THREAD());

以下を実行すると、たまに落ちます。

$ ./ruby
t = Thread.new do
loop do
w = IO.pipe.last
w.sync = false
w.write("a" * 1000)
end
end
sleep 0.1
Thread.new { }
GC.start

-:3: [BUG] object allocation during garbage collection phase
ruby 1.9.0 (2008-07-18 revision 18124) [i686-linux]

-- control frame ----------
c:0008 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC :(null)
c:0007 p:---- s:0013 b:0013 l:000012 d:000012 CFUNC :pipe
c:0006 p:0013 s:0010 b:0010 l:000f88 d:000009 BLOCK -:3
c:0005 p:---- s:0009 b:0009 l:000008 d:000008 FINISH
c:0004 p:---- s:0007 b:0007 l:000006 d:000006 CFUNC :loop
c:0003 p:0007 s:0004 b:0004 l:000f88 d:000003 BLOCK -:2
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:---- s:0002 b:0002 l:000001 d:000001 TOP

DBG> : "-:3:in (null)'" DBG> : "-:3:in pipe'"
DBG> : "-:3:in block (2 levels) in <main>'" DBG> : "-:2:in loop'"
DBG> : "-:2:in `block in '"
-- backtrace of native function call (Use addr2line) --
0x8102065
0x812948e
0x81294eb
0x8061b3a
0x806953c
0x80fdc90
0x80fe0f2
0x807e180
0x807e982
0x8066852
0x8059e20
0x806a768
0x80f2efe
0x80f4f4c
0x80f7eb9
0x80fbdcb
0x80fc414
0x80fc962
0x8059fec
0x80f4063
0x80f4f4c
0x80f7eb9
0x80fbdcb
0x80fc414
0x80fc784
0x8106b9c
0x8106be1
0xb7f6a240
0xb7e9e49e

アボートしました

原因は、T_FILE が GC されるとき

fptr_finalize
-> io_fflush
-> rb_thread_fd_writable
-> rb_thread_wait_fd_rw
-> do_select
-> BLOCKING_REGION

と呼び出しが進んで、GC 中に他のスレッドが動き出してしまうためです。

この問題がなかったとしても、fptr_finalize で io_fflush するのは
ブロックする可能性があってまずい気がします。どうしたもんでしょう。

--
Yusuke ENDOH
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0