Skip to main content

spawn_tracked

Function spawn_tracked 

Source
pub fn spawn_tracked(
    reap_tx: &Sender<Reaped>,
    spawn_fn: impl FnOnce() -> Result<Subagent>,
) -> Result<Subagent>
Expand description

Spawn a supervised child and register its pid → reap_tx atomically with the fork (both under the routes lock), so the reaper can never waitpid a child before it is registered. spawn_fn does the fork and returns the Subagent whose pid() is the registry key.

The lock is held across all of spawn_fn — the fork, the first-frame payload write, and the reader-thread spawn — so concurrent supervisors briefly serialize on each spawn. The hold is bounded by child startup (the child drains its stdin pipe within a few ms of exec), never by the length of a run, so spawn contention stays in the millisecond range.