Charles O Nutter wrote:
I should have a chance to look at your threading issues this weekend,
Werner. Things have been busy this week with a presentation and getting
Rails to run, but I'm going to circle back around to unhandled bugs.
Hi,
I was wondering if you had any time looking at this problem with
creating/accessing variables from different
threads (I attached the code that reproduces the problem again).
It seems that a variable created by an evaluation on Thread A is not
visible if you try to access
the variable from Thread B.
murphee
--
Blog @ http://jroller.com/page/murphee
Maintainer of EclipseShell @ http://eclipse-shell.sourceforge.net/
import org.jruby.IRuby;
import org.jruby.Ruby;
public class TestVariableCreation {
public static IRuby r;
public static Object object;
public static void main(String[] args) {
r = Ruby.getDefaultInstance();
// define new method
r.evalScript("def foo\n \"Hello\" \n end");
r.evalScript("a = 1\n");
r.evalScript("p a");
// will run on non main thread
Runnable run = new Runnable(){
public void run(){
try {
object = r.evalScript("p a");
} catch(Exception ex){
System.out.println(ex);
}
object = r.evalScript("a=2");
object = r.evalScript("p a");
}
};
Thread n = new Thread(run);
System.out.println("--------------- Calling Foo on Non-Main Thread --------------");
n.start();
try {
n.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
// Now from the same thread
System.out.println("----------- Calling from Thread ---------------");
object = r.evalScript("p a");
}
}