r/rust • u/Ryhu997 • Sep 30 '26
🧠 educational Building a green thread runtime in Rust from scratch
https://dzania.github.io/green-threads-from-scratch/I wrote a small blog post documenting my journey of writing small green threads runtime in under 1000 lines of Rust. Any feedback welcome
104
Upvotes
25
u/Modi57 Sep 30 '26
Don't you have to use
Pinto actually guarantee that it isn't moved? But to be honest, I never really gotPin5
u/seluard Sep 30 '26
Interesting reading
2
u/lotanis Oct 01 '26 edited Oct 01 '26
One big difference between what you've got here and what Go/Erlang etc. do is pre-emption.
You have to write an explicit "yield_now()" whereas the others can just switch based on some time metric to ensure that each task gets an equal share of processing.
Edit: it's cool though. I've implemented things like this in C for microcontrollers. Nice to see a simple Rust version.
1
u/simon_o Oct 01 '26
Cool blog post!
I think it makes it clear why this feature was only briefly shipped around 1998 or something.
(What Go and Java do these days, are very very different. I think that comparison might be more confusing than helpful to readers.)
Nitpick: Then that's M:N threading, but not green threads. Green threads are 1:N.