3 ms·
Nushell is the only shell I know of (other than fish) which uses threads. Threads are famously difficult in shells because of the fork/thread interaction. How
by ridiculous_fish 6y ago
Nushell is the only shell I know of (other than fish) which uses threads. Threads are famously difficult in shells because of the fork/thread interaction.
How is Nushell able to use threads? For example how are subshells implemented?
- vlmutolo 6y agoPart of it could be due to using Rust as the implementation language. Rust has good, cross-platform abstractions over things like threads and processes. The language tends to make it harder to shoot yourself in the foot. Would definitely like to hear from the authors of Nushell on how their language choice has held up over the course of the project.
- ridiculous_fish 6y agoA related issue is leaking fds into child processes. For example, Go locks around fork() to prevent racing with creating new fds (e.g. from pipe) [1]. Rust doesn't have any synchronization between fork and creating fds; I wonder whether/how this is addressed in nushell. 1: https://golang.org/src/syscall/exec_unix.go?s=7064:7143#L19 https://golang.org/src/syscall/exec_unix.go?s=7064:7143#L19
- Matthias247 6y agoMy guess it doesn't use fork, apart from spawning subprocesses use fork/exec combinations. The old fork idiom isn't exposed by Rusts standard libraries and also wouldn't be "safe" to use, since the basic expecatations of the language about how many things have access to a certain variable wouldn't hold up anymore.