/green-threads

Toy implementation of Green Threads based on https://cfsamson.gitbook.io/green-threads-explained-in-200-lines-of-rust

Primary LanguageRust

Green Threads

The 200-line implementation of green threads from this tutorial with comments about the details I learned.

TODO

  • Growable stacks
  • x86-64 psABI stack layout and calling convention
    • Q: how %rsp register works in stack construction in spawn()
      • when ret
      • when to move to next byte
    • A: Princeton COS217 slide on "Assembly Langauge: Function Calls"
  • why #[inline(never)] for switch()?
    • It's for stack alignment.

      In the perspective of one task, call switch sub %rsp for storing the %rip when suspended. When it's resumed, ret add %rsp back to the original aligned address.