On 22/11/2012 1:09 PM, Arlen Cuss wrote:
> Ah: prelude.rb defines Mutex#synchronize and Thread.exclusive in Ruby.
>
> prelude.rb is called by Init_prelude(), generated by tool/compile_prelude.rb, itself called by ruby_init_prelude() (in ruby.c).
>
> That in turn is called by ruby_process_options() (in ruby.c) which is called by ruby_options() (from eval.c). It's up to you which of the various ones you want to use, but ruby_init() followed by rb_eval_string() will leave you with a probably incomplete environment.
>
> You're already calling ruby_init_loadpath() yourself, for example, which would normally be done for you by ruby_process_options().
>
> (You could try the hacky method of calling ruby_init_prelude() yourself, too.)
>
>
Thanks for replying, Arlen.

I added a call to ruby_init_prelude() but it isn't declared in ruby.h so 
I got a compilation error.  I tried declaring it myself, but then it 
won't link because it's static in ruby.c.

I then tried calling ruby_process_options(int argc, char**argv). The 
first time I called it as ruby_process_options(0, 0). That causes a SEGV 
since it dereferences argv[0] even though argc is zero. This is arguably 
a bug, but anyway...

Next I called it with real argc and argv parameters with argc set to one 
- it hung reading from standard input (equivalent to just typing "ruby" 
at a shell prompt).

Finally, I faked the arguments as "ruby /dev/null" and it worked!!! I 
now get synchronized() defined. It's a bit clumsy having to fake the 
arguments, but beggars can't be choosers.

I'll go back to my original script and see whether it works.... Yes it does!

Thanks very much for your assistance,
     Graham