alexgutteridge / rsruby

Ruby - R bridge.
http://rubyforge.org/projects/rsruby/
GNU Lesser General Public License v2.1
332 stars 59 forks source link

Thread Safety #5

Closed ianschreuder closed 8 years ago

ianschreuder commented 13 years ago

Rsruby is not thread safe.

code:

require 'rsruby' Thread.new { rsruby = RSRuby.instance rsruby.rnorm(100) }.join

results in:

Error: C stack usage is too close to the limit Error: C stack usage is too close to the limit NoMethodError: R Function "get" not found ``from /usr/local/ruby-1.9.2-p180.aba/lib/ruby/gems/1.9.1/gems/rsruby-0.5.1.1/lib/rsruby.rb:97:inget_fun' from /usr/local/ruby-1.9.2-p180.aba/lib/ruby/gems/1.9.1/gems/rsruby-0.5.1.1/lib/rsruby.rb:97:in reset_cache' from /usr/local/ruby-1.9.2-p180.aba/lib/ruby/gems/1.9.1/gems/rsruby-0.5.1.1/lib/rsruby.rb:85:ininitialize' from /usr/local/ruby-1.9.2-p180.aba/lib/ruby/1.9.1/singleton.rb:109:in new' from /usr/local/ruby-1.9.2-p180.aba/lib/ruby/1.9.1/singleton.rb:109:inblock in instance' from internal:prelude:10:in synchronize' from /usr/local/ruby-1.9.2-p180.aba/lib/ruby/1.9.1/singleton.rb:107:ininstance' from (irb):3:in `block in irb_binding'


I suspect this is R's fault, but any insight you have would be appreciated.

Environment:
OS X - Lion and Snow Leopard
rsruby 0.5.1.1
R: 2.13.1
aaronjg commented 12 years ago

The stack limit checking does not work with multi-threading. RJava and RPython disable stack checking with: R_CStackLimit = (uintptr_t) -1;

matejuh commented 12 years ago

Where and how to set R_CStackLimit? Is it possible to do it to get RSRuby working it threads? For me its quite serious issue. If I run it in two system processes, it's ok... Do you think it's better way how to run it parallel?

aaronjg commented 12 years ago

I just checked in a fix disabling stack limit. You can check it out on my branch. However beware that R is not inherently multithreaded, so you may run into other issues.

matejuh commented 12 years ago

Thank you. It wasn't so big patch as I see. Btw. running RSRuby with processes made with Parallel gem haven't causes any problem yet. So this can be another way...

scho commented 12 years ago

I'm running into the same issue, but aaronjgs patch fixes this. When will this be integrated into alexgutteridges version of rsruby?

ghost commented 11 years ago

This took me a while to find. Turns out that when you're calling a method, via the rails runner capability...the issue disappears. It's only from within the WEBrick this occurs.

skiehl22 commented 10 years ago

I am also having the same problems. If aaronjg changes could be pushed into the main repo that would be greatly appreciated.

rapofran commented 9 years ago

thanks @aaronjg +1

phikes commented 9 years ago

Fix works, thanks! +1 for pulling that into the main repo.