Skip to content

Commit

Permalink
* io.c (fill_cbuf): finish reading at EOF, and the readconv has
Browse files Browse the repository at this point in the history
  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 ruby#3840

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jun 18, 2011
1 parent e623ceb commit 6effaa9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Sat Jun 18 23:59:24 2011 Nobuyoshi Nakada <[email protected]>

* 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 <[email protected]>

* thread_pthread.c: remove GVL_DEBUG
Expand Down
3 changes: 3 additions & 0 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,9 @@ fill_cbuf(rb_io_t *fptr, int ec_flags)
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);
Expand Down
20 changes: 20 additions & 0 deletions test/ruby/test_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1955,4 +1955,24 @@ def test_s_binwrite
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

0 comments on commit 6effaa9

Please sign in to comment.