2 ms·
I'm puzzled, too. The example is about spawning threads in Rust, not processes under UNIX. In Rust, if the main thread dies, all other threads get killed. So ch
by Animats 3y ago
I'm puzzled, too. The example is about spawning threads in Rust, not processes under UNIX. In Rust, if the main thread dies, all other threads get killed. So child threads outliving the main thread is not a problem.
A harder problem is making sure that the program shuts down if some thread panics. There are several ways to do that, but it's not automatic.
Incidentally, regular mutexes are "poisoned" if the thread holding them panics. Anyone trying to lock the mutex gets an error. However, parking_lot mutexes do not do this. If the thread holding one of those panics, the mutex unlocks. This may be unsafe.
- neandrake 3y agoI think the example is the code for a child process which must use a separate thread to block on stdin for the whole process. As soon as the parent process dies (no example code?), the connection to the child process’ stdin will be unblock, causing the child monitor thread to detect and panic.
- thecodedmessage 3y agoThe example is for the child process. The threads in Rust is meant as an implementation detail. This is super unclear and should’ve been explained.