Project

General

Profile

Bug #20863

Updated by ioquatix (Samuel Williams) 13 days ago

I was investigating some problems with `zlib.c` and GVL, and noticed that it releases the GVL, but still calls various `rb_` functions. According to my understanding, this is invalid. 

 I propose the following fix: https://github.com/ruby/zlib/pull/88 

 In addition, I think we should add more checks for this, in other words, we should add something like this to functions which are expected to only be called while the GVL is held: 

 ```c 
 RUBY_ASSERT(ruby_thread_has_gvl_p()) 
 ``` 

 I made a simple PR to demonstrate the change: https://github.com/ruby/ruby/pull/11975 

 While the current implementation is internal only (`ruby_thread_has_gvl_p` is not public interface), I think we should add this interface as a public macro, e.g. `RUBY_DEBUG_ASSERT_GVL` or something like that. This macro should be added to all methods that require the GVL in order to diagnose these issues. 

 Some ideas for public macro name: 

 - `RUBY_DEBUG_ASSERT_THREAD` 
 - `RUBY_DEBUG_ASSERT_CURRENT_THREAD` or `RUBY_DEBUG_ASSERT_CURRENT_THREAD_P` 
 - `RUBY_DEBUG_ASSERT_GVL` or `RUBY_DEBUG_ASSERT_GVL_P` 
 - `RUBY_DEBUG_ASSERT_LOCKED`

Back