From: Arlen Cuss Date: 2012-11-22T11:09:56+09:00 Subject: Re: "undefined method `synchronize' for #" from embedded Ruby program 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.) Arlen On Thursday, 22 November 2012 at 12:54 PM, Graham Menhennitt wrote: > On 21/11/2012 5:38 PM, Graham Menhennitt wrote: > > The error is: undefined method `synchronize' for # If I search back over this list's archives, I can see a few other people with the same problem (but no solution). #include int main(int argc, char *argv[]) { RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); rb_eval_string("$mutex = Mutex.new"); rb_eval_string("$mutex.synchronize(){}"); return 0; } I've done a bit more investigation and found that it happens in all 1.9 releases of Ruby, but it does NOT happen in 1.8.7. > > > The test program below produces: > > [:locked?, :try_lock, :lock, :unlock, :sleep, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] > > Whereas running "ruby -e 'p Mutex.new.methods'" produces: > > [:locked?, :try_lock, :lock, :unlock, :sleep, :synchronize, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] > > > Note that ":synchronize" is missing from the former. > > I've tried removing all gems in case one of them was doing something strange. I've searched the Ruby source code, but I can't see anything that might cause this. > > Anybody got any ideas? Should I take this to ruby.core? > > Thanks, > Graham > > Test program: > > #include > > > > int > > main(int argc, char *argv[]) > > { > > RUBY_INIT_STACK; > > ruby_init(); > > ruby_init_loadpath(); > > > > rb_eval_string("p Mutex.new.methods"); > > > > return 0; > > } >