mattn / mruby-thread

48 stars 31 forks source link

Reading from file descriptors kills threads #10

Closed postmodern closed 9 years ago

postmodern commented 10 years ago

I noticed that any reading of input within a thread will kill it.

Reproduction

t = Thread.new do
  puts "entering thread"
  puts STDIN.readline
  puts "leaving thread"
end

t.join

MRI 1.8.7 and 1.9.3

$ ruby test.rb
entering thread
hello
hello
leaving thread

mruby 1.0.0

$ ./mruby/bin/mruby test.rb
entering thread
mattn commented 10 years ago

I added bit code to migrate global_variables. But still not work. Because symbol value in another threads doesn't match as main thread's one. So you need to patch for mruby-io.

diff --git a/mrblib/io.rb b/mrblib/io.rb
index ca687ae..72fc019 100644
--- a/mrblib/io.rb
+++ b/mrblib/io.rb
@@ -146,10 +146,10 @@ class IO
   end

   def readline(arg = $/, limit = nil)
-    case arg
-    when String
+    case arg.class.to_s
+    when "String"
       rs = arg
-    when Fixnum
+    when "Fixnum"
       rs = $/
       limit = arg
     else
mattn commented 10 years ago

Ah, sorry. It's possible & done.

mattn commented 10 years ago

Ooops, it's not fixed.

mattn commented 9 years ago

Should be fixed in e139cfed05bbcbd5a37ff46c9994933cdd926e3e