From: "mdalessio (Mike Dalessio) via ruby-core" Date: 2023-05-02T15:31:53+00:00 Subject: [ruby-core:113393] [Ruby master Feature#19627] Add a way to detect if the Ruby VM is running in C API Issue #19627 has been updated by mdalessio (Mike Dalessio). I reported a related issue in https://bugs.ruby-lang.org/issues/19580 which I fixed with https://github.com/ruby/ruby/pull/7663 Maybe you want to explore a similar fix which will short-circuit functions like `rb_gc_adjust_memory_usage` instead of forcing callers to figure out if it's safe? ---------------------------------------- Feature #19627: Add a way to detect if the Ruby VM is running in C API https://bugs.ruby-lang.org/issues/19627#change-102965 * Author: ianks (Ian Ker-Seymer) * Status: Open * Priority: Normal ---------------------------------------- Currently, there is no supported way to check if the Ruby VM has been shut down. There are a couple of workarounds that I know of: 1. Setup an exit handler which sets a global variable (like I did in https://github.com/tmm1/stackprof/pull/200). 2. In Ruby 2.4 thru 3.2, you could check the hidden `ruby_vm_global_ptr != NULL`. For my use, in rb-sys there is a feature to automatically report Rust memory allocations via `rb_gc_adjust_memory_usage`. However, there is a bug that can cause processes to deadlock and/or segfault if a Rust destructor gets called after the VM quits (which can happen in Rust background threads). Currently, I don���t think there���s a way to safely make this feature work. (https://github.com/oxidize-rb/rb-sys/pull/205) It would be nice to have an official way to know if the Ruby VM is available, basically just a `ruby_current_vm_ptr != null`. Thoughts? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/