From 9f27336fcd2b9065c8a61fa1cbda6bb7290eb60e Mon Sep 17 00:00:00 2001 From: Tyler Smith <74526874+tylertms@users.noreply.github.com> Date: Tue, 20 Oct 2026 17:31:45 +0000 Subject: [PATCH] fix(hosted): keep a thread that ends its process active to the others until no guest code runs, as exit terminates the other threads first --- crates/stela-runtime/src/hosted/threads.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/stela-runtime/src/hosted/threads.rs b/crates/stela-runtime/src/hosted/threads.rs index 643e525efb..5a6ce88406 100644 --- a/crates/stela-runtime/src/hosted/threads.rs +++ b/crates/stela-runtime/src/hosted/threads.rs @@ -577,6 +577,7 @@ fn enter( }; drop(sender); let mut pe = pe; + let ends = EndsControl(&member.control); let outcome = run(&mut kernel, &mut pe, &member); *lock(&process.runtime.statistics) += pe.statistics; process.exception_ports.thread_ended(port); @@ -602,6 +603,7 @@ fn enter( process.aio.exit(); process.runtime.end(id, Ok(Termination::Exited(0))); } + drop(ends); } /// Take the execution lock for the thread and bring its engine up to date: @@ -642,7 +644,12 @@ fn restart_ranges(process: &Process, pe: &mut Pe) { } } -/// Marks the thread's control ended however [`run`] returns. +/// Marks the thread's control ended however its host thread leaves the +/// guest thread: after the process's end, when the thread ended it, so +/// that the thread stays active to the others until no guest code runs +/// (`exit` terminates the task's other threads before the exiting one, +/// `task_terminate_internal`; a `thread_suspend` of it until then +/// succeeds). struct EndsControl<'a>(&'a Control); impl Drop for EndsControl<'_> { @@ -660,7 +667,6 @@ fn run(kernel: &mut Kernel, pe: &mut Box, member: &Member) -> Result