From: Robert Klemme Date: 2010-11-16T19:27:12+09:00 Subject: Re: Embedding ruby interpreter On Tue, Nov 16, 2010 at 11:24 AM, Steve Hart wrote: > 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. This is no longer true with 1.9. 1.9 uses native threads (although there's still the GIL which slows it somewhat down). I do not know how best to interact but I guess you could find hints by looking at thread creation code. > 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? See above. > 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. Others can certainly give more detailed advice but my quick heads up might send you in the right direction. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/