From: "ioquatix (Samuel Williams) via ruby-core" Date: 2024-01-03T23:40:11+00:00 Subject: [ruby-core:116001] [Ruby master Feature#20102] Introduce `Fiber#resuming?` Issue #20102 has been updated by ioquatix (Samuel Williams). @Eregon I appreciate your input. I don't mind doing that, but isn't that the same for all methods on Fiber? In other words, the GVL provides a bit of a safety net. Should we apply this model to other methods? Maybe we need to define what methods can be called safely from one thread or another. What about if a user has a mutex to control access, or the fiber/thread is not actually running at the time of the call? I assume there is a lot of historical context/implementation where such behaviour is just racy but nothing is done to protect it. In other words, I feel like the problem you are trying to address spans almost all of Ruby's mutable state... tricky. ---------------------------------------- Feature #20102: Introduce `Fiber#resuming?` https://bugs.ruby-lang.org/issues/20102#change-105996 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal * Assignee: ioquatix (Samuel Williams) ---------------------------------------- There are some tricky edge cases when using `Fibre#raise` and `Fiber#kill`, e.g. ```ruby fiber = nil killer = Fiber.new do fiber.raise("Stop") end fiber = Fiber.new do killer.resume end fiber.resume # 4:in `raise': attempt to raise a resuming fiber (FiberError) # 4:in `block in
' ``` Async has to deal with this edge case explicitly by rescuing the exception: https://github.com/socketry/async/blob/ffd019d9c1d547926a28fe8f36bf7bfe91d8a168/lib/async/task.rb#L226-L233 I'd like to avoid doing that and instead just ask "Can I kill/raise on this fiber right now?" which is determined by whether the fiber itself can be resumed or transferred to. To address this, I'd like to introduce `Fiber#resuming?`: ```c /* * call-seq: fiber.resumed? -> true or false * * Whether the fiber is currently resumed. */ VALUE rb_fiber_resuming_p(VALUE fiber_value) { struct rb_fiber_struct *fiber = fiber_ptr(fiber_value); if (FIBER_TERMINATED_P(fiber)) return RUBY_Qfalse; return RBOOL(fiber->resuming_fiber); } ``` See the PR: https://github.com/ruby/ruby/pull/9382 -- 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/