Skip to content

fix(task): self-termination now triggers context switch#6923

Closed
ARYA-mgc wants to merge 1 commit into
mruby:masterfrom
ARYA-mgc:fix/terminate-self-context-switch
Closed

fix(task): self-termination now triggers context switch#6923
ARYA-mgc wants to merge 1 commit into
mruby:masterfrom
ARYA-mgc:fix/terminate-self-context-switch

Conversation

@ARYA-mgc

@ARYA-mgc ARYA-mgc commented Jul 4, 2026

Copy link
Copy Markdown

terminate_task_internal() moved the task to the dormant queue before checking t == q_ready_ for the context-switch decision. Since the task was already removed from the ready queue, the comparison was always false, leaving a self-terminated task running as a zombie until the next natural exit point.

Capture was_running before the queue transition and use it for the switch decision.

Part of #6922 (see issue for a related sleep()-suspends-wrong-task bug, filed as a separate PR).

terminate_task_internal() moved the task to the dormant queue
before checking `t == q_ready_` for the context-switch decision.
Since the task was already removed from the ready queue, the
comparison was always false, leaving a self-terminated task
running as a zombie until the next natural exit point.

Capture `was_running` before the queue transition and use it
for the switch decision.
@ARYA-mgc ARYA-mgc requested a review from matz as a code owner July 4, 2026 17:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the task termination logic in task.c to determine if a task was running before its status is set to dormant, using this state to trigger a context switch. Additionally, a test case has been added in task.rb to verify that self-termination correctly switches context to the next task. There are no review comments, so no feedback is provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@matz

matz commented Jul 4, 2026

Copy link
Copy Markdown
Member

Thanks for the careful write-up in #6922, this was a clean catch. The t == q_ready_ check could never be true after the task had already been moved to the dormant queue, so a self-terminated task really did run one extra statement. Capturing was_running before the transition matches how suspend_task_internal already decides on the switch.

Merged into master as 7156895 (I pushed the reviewed commit directly together with #6924, since the two touched the same tail of test/task.rb). The regression test is in too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants