I know that in ruby (due to green threads), timeout.rb is a mess when
dealing with system calls, but I thought (until now) that in jruby did
not exist this problem.
I’m gonna use ffi to be able to use native code:
sleep_c.c:
// If input parameter is 0, infinite loop, otherwise sleep x seconds
void sleep_c(int s)
{
if ( ! s ) while (1) ++s;
sleep(s);
}
gcc -shared sleep_c.c -o libsleep_c.so
sleep.rb:
require ‘ffi’
module Foo
extend FFI::Library
ffi_lib File.join(File.dirname(FILE), “libsleep_c.so”)
attach_function :sleep_c, [:int], :void
end
require ‘timeout’
Timeout.timeout(1) do
timeout = ARGV[0].to_i
Foo.sleep_c timeout
end
If you execute jruby sleep_c.rb 2 (a sleep 2 system call is executed)
will end with timeout exception as expected, ok. But, if you execute
jruby sleep_c.rb 0 (infinite loop in native code), it will never end.
Is this a problem with jruby, with ffi or with something else?
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email