I tried to call an external library which worked in older version of Ruby 
On Rails with DL, but I couldn't get it working in newer version of Ruby On 
Rails using fiddle, the error message is "stack level too deep". I tried 
several new versions of Ruby without success. After some digging, it seems 
that it works in Ruby script, but not if I use thread, see codes posted 
below, I suspect that it might be an issue with stack size (when use 
thread) ? I actually tried to comment out codes to generate newer external 
library to find out where the crash is, and find that the program crashes 
at a loop with 20000 loops when computing entries for a 4X20000 matrix. Any 
advice to fix this? Thanks!

Working ruby script:

require 'fiddle/import'

module Libm
extend Fiddle::Importer
dlload '/Library/WebServer/smart/lib/libsamplesize.dylib'
extern 'long Calculate(long, double, double, char*)'
end

errmsg = " "

puts Libm.Calculate( 1000, 0.2, 0.9, errmsg)

Not working in thread:

require 'fiddle/import'

module Libm
extend Fiddle::Importer
dlload '/Library/WebServer/smart/lib/libsamplesize.dylib'
extern 'long Calculate(long, double, double, char*)'
end

puts "Started At #{Time.now}"
errmsg = " " 
thr1=Thread.new{ puts Libm.Calculate( 1000, 0.2, 0.9, errmsg)}
thr1.join
puts "End at #{Time.now}"

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/17ab8be0-571f-42da-83c0-1fbedc9810b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to