diff --git a/src/runtime.rs b/src/runtime.rs index 3baf993..a980420 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -967,16 +967,27 @@ impl Runtime { self.inner.root_swept.store(false, Ordering::Relaxed); self.inner.set_root(initial_handle.pid()); - // Launch N-1 extra scheduler threads. The calling thread is thread 0. + // Launch N-1 extra scheduler threads, named `smarm-sched-{slot}` so + // they are identifiable in `/proc//task/*/comm`, stack dumps and + // debuggers. The calling thread is thread 0 and keeps its caller-given + // name (an embedder typically names it when spawning `run`). let mut os_threads = Vec::new(); for slot in 1..self.thread_count { let inner = self.inner.clone(); - let t = thread::spawn(move || { - RUNTIME.with(|r| *r.borrow_mut() = Some(inner.clone())); - SCHED_SLOT.with(|s| s.set(slot)); - schedule_loop(&inner, slot); - RUNTIME.with(|r| *r.borrow_mut() = None); - }); + let t = thread::Builder::new() + .name(format!("smarm-sched-{slot}")) + .spawn(move || { + RUNTIME.with(|r| *r.borrow_mut() = Some(inner.clone())); + SCHED_SLOT.with(|s| s.set(slot)); + schedule_loop(&inner, slot); + RUNTIME.with(|r| *r.borrow_mut() = None); + }); + // `thread::spawn` (the previous form) also panics when the OS + // refuses a thread, so this keeps the failure semantics. + let t = match t { + Ok(t) => t, + Err(e) => panic!("failed to spawn smarm scheduler thread: {e}"), + }; os_threads.push(t); }