Issue #22098 has been updated by Eregon (Benoit Daloze). From https://github.com/ruby/ruby/blob/c2879d4eb1c2f232c893656a49a2c53353aebf04/i... ```c /** * Triggered when a new thread is started. * * @note The callback will be called *without* the GVL held. */ #define RUBY_INTERNAL_THREAD_EVENT_STARTED 1 << 0 /** * Triggered when a thread attempt to acquire the GVL. * * @note The callback will be called *without* the GVL held. */ #define RUBY_INTERNAL_THREAD_EVENT_READY 1 << 1 /** acquiring GVL */ /** * Triggered when a thread successfully acquired the GVL. * * @note The callback will be called *with* the GVL held. */ #define RUBY_INTERNAL_THREAD_EVENT_RESUMED 1 << 2 /** acquired GVL */ /** * Triggered when a thread released the GVL. * * @note The callback will be called *without* the GVL held. */ #define RUBY_INTERNAL_THREAD_EVENT_SUSPENDED 1 << 3 /** released GVL */ /** * Triggered when a thread exits. * * @note The callback will be called *without* the GVL held. */ #define RUBY_INTERNAL_THREAD_EVENT_EXITED 1 << 4 /** thread terminated */ ``` * `RUBY_INTERNAL_THREAD_EVENT_RESUMED` is explicitly documented as having the GVL. * `RUBY_INTERNAL_THREAD_EVENT_STARTED` is documented as being called without the GVL, but it seems to be called on the parent thread with the GVL. Documentation bug then? ---------------------------------------- Bug #22098: RUBY_INTERNAL_THREAD_EVENT_RESUMED runs without GVL held https://bugs.ruby-lang.org/issues/22098#change-117684 * Author: luke-gru (Luke Gruber) * Status: Open * Assignee: luke-gru (Luke Gruber) * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- Today, it's possible to get a deadlock when allocating during a hook for this event. I attached a reproduction script using the `gvltools` gem. One way to fix it would be to not allocate during this hook and change the documentation to be clear that the GVL is not held. Any gems relying on this behavior, like `gvltools`, would need to be patched. Another way to approach it would be to change the call site for this hook invocation. I believe it would need to be added to quite a few places. To maintain Ractor safety, it would also need to be invoked without any locks held. I'm curious about your thoughts @byroot. ---Files-------------------------------- repro.rb (3.11 KB) run_loop.sh (2.82 KB) -- https://bugs.ruby-lang.org/