Repository navigation
vm.c: tell the end of a task body from a fiber's by owner, not status - #7845
Conversation
## Background At the return from the base frame, the VM decided that a task body had ended by `mrb->c->status == MRB_TASK_CREATED`, and sent everything else to fiber_terminate(). A task's own context keeps CREATED only until it resumes a fiber: fiber_switch() writes RESUMED over it, and RUNNING when the fiber returns. So the body of a task that had resumed any fiber ended in fiber_terminate(), which freed the task's call info, stack and svars. The task still stopped with the same status value, so a task used once showed nothing. A task run again on its context does show it. picoruby-sandbox runs each irb line on one task with mrb_task_reset_context() and mrb_task_proc_set(). After a line that resumed a fiber (an Enumerator#next is enough), the context had no call info, so the scheduler retired the task at once: no later line ran, and every one answered the value of the line with the fiber. ## Fix Tell the two by owner: a fiber's context always holds its RFiber in c->fib, and a task's own context holds none, or the one Fiber.current borrowed for it. This is the test mrb_task_across_c_boundary() already uses for the same question. TaskTest.rerun drives the sandbox sequence (suspend, reset_context, proc_set, resume), and a test runs a task again after it resumed a fiber, and after it left one suspended.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Background
At the return from the base frame, the VM decided that a task body had ended by
mrb->c->status == MRB_TASK_CREATED, and sent everything else to fiber_terminate(). A task's own context keeps CREATED only until it resumes a fiber: fiber_switch() writes RESUMED over it, and RUNNING when the fiber returns. So the body of a task that had resumed any fiber ended in fiber_terminate(), which freed the task's call info, stack and svars. The task still stopped with the same status value, so a task used once showed nothing.A task run again on its context does show it. picoruby-sandbox runs each irb line on one task with mrb_task_reset_context() and mrb_task_proc_set(). After a line that resumed a fiber (an Enumerator#next is enough), the context had no call info, so the scheduler retired the task at once: no later line ran, and every one answered the value of the line with the fiber.
Fix
Tell the two by owner: a fiber's context always holds its RFiber in c->fib, and a task's own context holds none, or the one Fiber.current borrowed for it. This is the test mrb_task_across_c_boundary() already uses for the same question.
TaskTest.rerun drives the sandbox sequence (suspend, reset_context, proc_set, resume), and a test runs a task again after it resumed a fiber, and after it left one suspended.
Summary by CodeRabbit