-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
relax Fiber#transfer's restriction #3636
Conversation
012e9f9
to
f307a72
Compare
35defef
to
f008d5a
Compare
test/ruby/test_fiber.rb
Outdated
@@ -409,5 +480,5 @@ def test_machine_stack_gc | |||
sleep 5 # pause until thread cache wait time runs out. Native thread exits. | |||
GC.start | |||
RUBY | |||
end | |||
end if false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional?
end | ||
ruby_version_is '3.0' do | ||
fiber2.resume.should == :fiber2 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to have ruby_version_is
outside of it "description" do
, so the description can explain the difference in behavior. I can do that after this PR is merged.
cont.c
Outdated
rb_raise(rb_eFiberError, "attempt to transfer to a resuming fiber"); | ||
} | ||
if (fiber->yielding) { | ||
rb_raise(rb_eFiberError, "attempt to transfer to an yielding fiber"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to a yielding fiber
(replied on Redmine)
cceb892
to
6b7bd36
Compare
Using Fiber#transfer with Fiber#resume for a same Fiber is limited (once Fiber#transfer is called for a fiber, the fiber can not be resumed more). This restriction was introduced to protect the resume/yield chain, but we realized that it is too much to protect the chain. Instead of the current restriction, we introduce some other protections. (1) can not transfer to the resuming fiber. (2) can not transfer to the yielding fiber. (3) can not resume transferred fiber. (4) can not yield from not-resumed fiber. [Bug #17221] Also at the end of a transferred fiber, it had continued on root fiber. However, if the root fiber resumed a fiber (and that fiber can resumed another fiber), this behavior also breaks the resume/yield chain. So at the end of a transferred fiber, switch to the edge of resume chain from root fiber. For example, root fiber resumed f1 and f1 resumed f2, transferred to f3 and f3 terminated, then continue from the fiber f2 (it was continued from root fiber without this patch).
6b7bd36
to
cf3395e
Compare
Using Fiber#transfer with Fiber#resume for a same Fiber is
limited (once Fiber#transfer is called for a fiber, the fiber
can not resume more). This restriction is introduced to protect
the resume/yield chain, but we realized that it is too much to
protect the resume/yield chain. Instead of the current restriction,
we introduce some other protection.
(1) can not transfer to the resuming fiber.
(2) can not transfer to the yielding fiber.
(3) can not resume transferred fiber.
https://bugs.ruby-lang.org/issues/17221