Project

General

Profile

Actions

Feature #20750

open

Allow rb_thread_call_with_gvl to work when thread already has GVL

Added by kbrock (Keenan Brock) 3 months ago. Updated 3 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:119239]

Description

Hello All,

I'm hoping we can make ruby_thread_has_gvl_p a public method and no longer experimental.

I saw the following code in a gem that was not compiling with ruby 3.3:

// int ruby_thread_has_gvl_p(void); // <== line of concern
  if (ruby_thread_has_gvl_p()) {
    method_call(&context);
  }
  else {
    rb_thread_call_with_gvl(method_call, &context);
  }

400 unique projects on github added the line listed above to fix compilation. 1

Some of the projects detected the method first in extconf.rb, but a majority just referenced it.
ffi used to have the detection code but dropped it since the method was in all supported ruby versions.

It feels like this method is now part of the undocumented public interface.
My suggestion is to add the method to the real public interface in ruby/thread.h.

PR with possible solution: https://github.com/ruby/ruby/pull/11619
Also included a patch if that is easier

Thank you for your consideration,
Keenan

Timeline:

  • Dec 30 2008 - rb_thread_call_with_gvl introduced via 9c04a06 2
  • Jan 12 2009 - ruby_thread_has_gvl_p introduced via 6f09fc2 4
  • Jul 18 2012 - rb_thread_call_with_gvl made public via e9a91d2 3

Current references to code: rb_thread_call_with_gvl 5 ruby_thread_has_gvl_p 6:


Files

11618.patch (3.18 KB) 11618.patch Old Solution kbrock (Keenan Brock), 09/17/2024 04:52 PM
11649-lenent-rb_thread_call_with_gvl.patch (1.26 KB) 11649-lenent-rb_thread_call_with_gvl.patch Suggested Solution kbrock (Keenan Brock), 09/19/2024 04:37 PM
11649b-additional-changes.patch (2.91 KB) 11649b-additional-changes.patch Optional Addition kbrock (Keenan Brock), 09/19/2024 04:37 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like1Like0Like0