Green threads explained in 200 lines of Rust
cfsamson.gitbook.io
Green threads explained in 200 lines of Rust
1–10 of 48 posts
Re: Green threads explained in 200 lines of Rust
#2Re: Green threads explained in 200 lines of Rust
#3It does make me thinking about how this could be useful in the context of Futures and async/await.
Re: Green threads explained in 200 lines of Rust
#4Re: Green threads explained in 200 lines of Rust
#5Anecdote: almost a decade ago, I was responsible for an NVMe-like implementation (hard- and software). The 3rd version of the firmware recognized the various components as threads, but there was no need for preemption (which would require expensive locking). Traditional scheduling would work, but you actually know exactly which thread should execute next (hardware will signal done), so an explicit yield_to() was far cheaper and only slightly more expensive than a function call.
Re: Green threads explained in 200 lines of Rust
#6Isn't one downside that the inline assembly will not be peephole-optimized by the code generator (LLVM)? E.g., you'd be saving and restoring registers that are not even used.
Re: Green threads explained in 200 lines of Rust
#7Isn't one downside that the inline assembly will not be peephole-optimized by the code generator (LLVM)? E.g., you'd be saving and restoring registers that are not even used.
> a simple but working example
The goal should be to have a green thread library that you can just use without thinking about registers or assembly.
Re: Green threads explained in 200 lines of Rust
#8Co-routines are very useful and likely underused, but sometimes you are actually better off being able to pass the control to a given thread directly, other than having a scheduler involved. Anecdote: almost a decade ago, I was responsible for an NVMe-like implementation (hard- and software). The 3rd version of the firmware recognized the various components as threads, but there was no need for preemption (which woul…
Re: Green threads explained in 200 lines of Rust
#9Earlier quoted context omitted.
> a simple but working example
Yeah, of course, but how would you work this type of code into something that can be used in production? The goal should be to have a green thread library that you can just use without thinking about registers or assembly.
lol
Re: Green threads explained in 200 lines of Rust
#10Earlier quoted context omitted.
> a simple but working example
Yeah, of course, but how would you work this type of code into something that can be used in production? The goal should be to have a green thread library that you can just use without thinking about registers or assembly.
You wouldn't. There are production-ready solutions to this in many languages.
> The goal should be to have a green thread library that you can just use without thinking about registers or assembly.
The goal here is very explicitly to explain a concept by example, which is largely incompatible with what you say the goal should be. I think the author did a very good job.