Threads without the kernel cost
A green thread, sometimes called a virtual thread or fiber, is a thread managed entirely by a runtime in user space rather than by the operating system. Many green threads are multiplexed onto a small pool of real OS threads, a layout often called M to N scheduling.
Why they are cheap
- An OS thread reserves a large stack and needs a kernel context switch to swap.
- A green thread starts with a tiny stack that grows on demand, so you can create hundreds of thousands.
- Switching between green threads happens in user space and skips the kernel, so it is far faster.
How blocking is handled
The runtime watches for blocking operations. When a green thread waits on input or output, the runtime parks it and runs another green thread on the same OS thread, keeping the core busy. The OS thread itself never actually blocks on that call.
Key idea
Green threads are user space threads multiplexed M to N onto a few OS threads, with tiny growable stacks and user space switching that make hundreds of thousands of concurrent tasks practical.