From: Eric Wong Date: 2012-05-25T10:21:20+09:00 Subject: Re: [C exten] Could Ruby GC my VALUE in while acquiring the GVL? I単aki Baz Castillo wrote: > Hi, I'm in C land without GVL and give value to a static VALUE > variable defined in my .c file and later I acquire the GVL and want to > use such a VALUE variable: > > > // GVL release here: > > static VALUE my_variable; Static variables in C are global to the process and not on the stack, so yes, all static VALUEs need to be registered with GC (rb_global_variable/rb_gc_register_address) > my_variable = rb_new_str("hello", 5); rb_str_new() is not safe to call without GVL. > rb_thread_call_with_gvl(function_with_gvl, NULL); > So my question is: could Ruby GC my_variable while acquiring the GVL? > should I keep it from GC by using rb_gc_register_address(&my_variable) Yeah, Ruby can GC your variables at _any_ time. Keep in mind rb_global_variable/rb_gc_register_address/rb_new_str/... all require GVL to function safely (always assume Ruby C API requires the GVL, only a few C API functions are explicitly marked as thread-safe).