I would like to run the Matlab engine (using the gem matlab-ruby) inside a ruby thread. The idea is to use ruby to distribute my Matlab processes onto different cores. However when I try to start a new engine from inside a thread I get a Trace/BPT trap: 5 error.
I’m new to ruby so not that strong on threads and so forth. Is what I’m trying to do possible or is it just one of those things that can’t be done?
require ‘matlab’
t1=Thread.new do
engine = Matlab::Engine.new
engine.put_variable "x", 10
engine.put_variable "y", 22
engine.eval "z = x * y"
puts engine.get_variable "z"
end
t1.join
I wonder what happens if you instantiate a
Matlab::Enginein the main thread, then later run your code as-is:I ask because I’ve had trouble with Trace/BPT with different libraries (Sinatra/ActiveRecord/pg/etc.), and when running Ruby in GBD, it crashed with the following backtrace:
Searching around lead me to this bug report for SBCL which suggests that dynamic libraries may only be loaded by the main thread.