From: Steve Hart Date: 2010-11-16T19:24:02+09:00 Subject: Embedding ruby interpreter Hi We are looking at upgrading our current version of ruby 1.8.7 to latest 1.9.2-p0, We have been running ruby embedded within a pthread with a swigged up interface for about 7 years and it has worked fine. On changing to 1.9 we get a crash on initialistaiion the first time the gc is called. This occurs in mark_current_machine_context Under 1.8.7 we initialised the ruby thread thus int ScriptThread::run() { int addr; ruby_init(); Init_stack((void *)&addr); ruby_script("embedded"); ruby_init_loadpath(); Init_gm(); // swigged up interface ..... } Under 1.9 I changed this to: RUBY_GLOBAL_SETUP int ScriptThread::run() { //ruby_sysinit(&argc, &argv); // commented out, no args available { RUBY_INIT_STACK; ruby_init(); } Init_gm(); ..... } Note that our thread is created thru QT using pthreads. We also compile 1.8.7 without pthread support. Our interpreter runs exclusively in this thread and all VALUE's created in C are properly wrapped and marked. I have read the threads from http://www.ruby-forum.com/topic/144747 http://redmine.ruby-lang.org/issues/show/2294 From these it would appear that a) The ruby initialisation must be done in main Is this a change from 1.8.7? What if we are dynamically loaded and have no access to main? b) The thread should be created using rb_thread_create Is this true? If so, why? c) disabling pthread support when compiling ruby has been deprecated. What does this mean? - Does ruby use threads itself? I briefly tried to disable the gc and then got a crash d) Should we apply the patch from 2294? What is the correct way to do this? I would greatly appreciate any help anyone could give. -- Posted via http://www.ruby-forum.com/.