From 33fc4cb4dca7432744d3192a2e3377a1907594e8 Mon Sep 17 00:00:00 2001 From: Szymon Kaliski Date: Wed, 24 Jan 2024 10:49:15 +0100 Subject: [PATCH] a comment --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ee45a2c..fbbc611 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,6 +131,19 @@ impl Pty { let pid = child.id(); + // We're creating a new thread for every child, this uses a bit more system resources compared + // to alternatives (below), trading off simplicity of implementation. + // + // The altneratives: + // - Mandate that every single `wait` goes through a central process-wide loop that knows + // about all processes (this is what `pid1` does), but needs a bit of care and some static + // analysis to ensure that every single call goes through the wrapper to avoid double `wait`'s + // on a child. + // - Have a single thread loop where other entities can register children (by sending the pid + // over a channel) and this loop can use `epoll` to listen for each child's `pidfd` for when + // they are ready to be `wait`'ed. This has the inconvenience that it consumes one FD per child. + // + // For discussion check out: https://github.com/replit/ruspty/pull/1#discussion_r1463672548 thread::spawn(move || match child.wait() { Ok(status) => { if status.success() {