Thread.status == 'run' while some blocking IO
---------------------------------------------

                 Key: JRUBY-5238
                 URL: http://jira.codehaus.org/browse/JRUBY-5238
             Project: JRuby
          Issue Type: Improvement
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.5.5
         Environment: jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2010-12-03 
9cf97c3) (OpenJDK 64-Bit Server VM 1.6.0_20) [amd64-java]

            Reporter: Hiroshi Nakamura
            Assignee: Hiroshi Nakamura


Thread.status is 'run' while blocking read/write. It should be 'sleep' though 
Threads of JRuby actually sleeps. (No busy loop: CPU 0%)

It's just a cosmetic state management but it's the only way to check if Thread 
is blocking or not in Ruby.

{noformat}
require 'socket'
require 'timeout'

server = TCPServer.new('127.0.0.1', 0)
port = server.addr[1]
client = TCPSocket.new('127.0.0.1', port)
r = Thread.new {
  client.read
}
w = Thread.new {
  # write enough bytes to block.
  client.write("foo\n" * 1000000);
  # JRuby on Windows does not block here.
}

def wait_block(t)
  begin
    timeout(2) do
      sleep 0.1 while t.status != 'sleep'
    end
  rescue Timeout::Error
    raise 'Thread is running...'
  end
end

begin
  wait_block(r)
  wait_block(w)
ensure
  p(Thread.list - [Thread.current]) #=> sleep(read), sleep(write)
end
{noformat}

{noformat}
0% ruby187 -v rw.rb 
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
[#<Thread:0x7f766eecf298 sleep>, #<Thread:0x7f766eecf388 sleep>]

0% ruby -v rw.rb 
ruby 1.9.3dev (2010-11-26 trunk 29941) [x86_64-linux]
[#<Thread:0x00000001a955a0 sleep>, #<Thread:0x00000001a95528 sleep>]

0% jruby -v rw.rb
jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2010-12-03 9cf97c3) (OpenJDK 64-Bit 
Server VM 1.6.0_20) [amd64-java]
bin/jruby [#<Thread:0x7219d6afrun>, #<Thread:0x7e5db5aerun>, 
#<Thread:0x3a42f352run>]
rw.rb:25:in `wait_block': Thread is running... (RuntimeError)
        from rw.rb:30
1% bin/jruby -v rw.rb
jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-12-04 2130381) (OpenJDK 
64-Bit Server VM 1.6.0_20) [linux-amd64-java]
[#<Thread:0x21719f30 sleep>, #<Thread:0x2a8a1977 sleep>]
0% 
{noformat}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to