ruby-changes:20121
From: nobu <ko1@a...>
Date: Sun, 19 Jun 2011 00:00:26 +0900 (JST)
Subject: [ruby-changes:20121] nobu:r32169 (trunk): * io.c (fill_cbuf): finish reading at EOF, and the readconv has
nobu 2011-06-19 00:00:00 +0900 (Sun, 19 Jun 2011) New Revision: 32169 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32169 Log: * io.c (fill_cbuf): finish reading at EOF, and the readconv has been cleared by another thread while io_fillbuf() is waiting at select(). a patch in [ruby-core:37197] by Hiroshi Shirosaki <h.shirosaki AT gmail.com>. fixed #3840 Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32168) +++ ChangeLog (revision 32169) @@ -1,3 +1,10 @@ +Sat Jun 18 23:59:24 2011 Nobuyoshi Nakada <nobu@r...> + + * io.c (fill_cbuf): finish reading at EOF, and the readconv has + been cleared by another thread while io_fillbuf() is waiting at + select(). a patch in [ruby-core:37197] by Hiroshi Shirosaki + <h.shirosaki AT gmail.com>. fixed #3840 + Sat Jun 18 21:36:29 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * thread_pthread.c: remove GVL_DEBUG Index: io.c =================================================================== --- io.c (revision 32168) +++ io.c (revision 32169) @@ -1717,6 +1717,9 @@ if (fptr->rbuf.len == 0) { READ_CHECK(fptr); if (io_fillbuf(fptr) == -1) { + if (!fptr->readconv) { + return MORE_CHAR_FINISHED; + } ds = dp = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.off + fptr->cbuf.len; de = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.capa; res = rb_econv_convert(fptr->readconv, NULL, NULL, &dp, de, 0); Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 32168) +++ test/ruby/test_io.rb (revision 32169) @@ -1955,4 +1955,24 @@ assert_nothing_raised(TypeError) { File.binwrite(path, "string", mode: "w", encoding: "EUC-JP") } end end + + def test_race_between_read + file = Tempfile.new("test") + path = file.path + file.close + write_file = File.open(path, "wt") + read_file = File.open(path, "rt") + + threads = [] + 10.times do |i| + threads << Thread.new {write_file.print(i)} + threads << Thread.new {read_file.read} + end + threads.each {|t| t.join} + assert(true, "[ruby-core:37197]") + ensure + read_file.close + write_file.close + file.close! + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/