Threads the kernel cannot see
A green thread, sometimes called a fiber, is a unit of execution scheduled by a language runtime or library rather than by the operating system kernel. The kernel sees only the few real OS threads underneath; it has no idea how many green threads ride on top.
Why they are cheap
Because the runtime manages them, green threads can be tiny:
- Small stacks that start at a few kilobytes and grow on demand.
- Fast switches that stay in user space and never enter the kernel.
- Many at once, often hundreds of thousands, where OS threads would exhaust memory.
The catch with blocking
The runtime usually switches a green thread only at known points, such as awaiting input or yielding. If one green thread makes a blocking system call without yielding, it can freeze the OS thread carrying it, stalling every green thread parked there. Good runtimes wrap blocking calls or hand them to a dedicated pool to avoid this trap.
Key idea
Green threads are lightweight tasks the runtime schedules in user space, letting a program run huge numbers of them cheaply as long as blocking calls are handled with care.