Skip to content

Ease fiber limitations - #6106

Merged
matz merged 6 commits into
mruby:masterfrom
dearblue:fiber-limits-ease
Dec 13, 2023
Merged

Ease fiber limitations#6106
matz merged 6 commits into
mruby:masterfrom
dearblue:fiber-limits-ease

Conversation

@dearblue

@dearblue dearblue commented Dec 4, 2023

Copy link
Copy Markdown
Contributor

Neutralizes restriction #5782 introduced by Fiber#resume issue #5781.

ref. #6063

The main objective is to make sure that fiber can be handled from C.

Also, add a mechanism to detect that the mruby VM has stopped in the middle of the process.
If it stops halfway, the test will be terminated with `abort()`.
This patch is effectively reverts to the following:
  - commit dc65b1f (mruby#5782)
  - commit f4c4809 (mruby#5947)

Ref. mruby#6063
If `mrb_fiber_resume()` was called from a C function as a method definition, the mruby VM was not processed afterwards.

    Called Fiber.yield
    mrb_vm_exec()       <<-- returns from the function by CINFO_RESUMED
    fiber_switch()      <<-- this patch causes the value to return to its pre-call state
    mrb_fiber_resume()
    mrb_vm_exec()       <<-- previously, returns from the function immediately as it was CINFO_RESUMED
    ...
    main()
Need to return control from `mrb_vm_exec()` to the caller if `Fiber#resume` was done from C.
When a fiber switched by `Fiber.yield` is resumed by `Fiber#resume` by C, it is necessary to pop CI with `fiber_switch()`.
Previously, CI misalignment caused inconsistencies, including crashes, on the next `Fiber#resume`.
Previously, if the caller of `Fiber#resume` had a C function call, an inconsistency would occur.
@dearblue
dearblue requested a review from matz as a code owner December 4, 2023 13:58
@matz
matz merged commit 5311d1a into mruby:master Dec 13, 2023
@dearblue
dearblue deleted the fiber-limits-ease branch December 15, 2023 13:02
dearblue added a commit to dearblue/mruby that referenced this pull request Mar 8, 2024
Assertions were failing on exit if started with `mrb_fiber_resume()`.

The bug that caused it was introduced by commit 42308c4 (mruby#6106).
The bug was moved by commit 990e18a.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants