← Lessons

quiz vs the machine

Gold1380

Concurrency

The Green Thread Scheduling

Lightweight threads scheduled in user space and mapped onto a few OS threads.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What does M to N scheduling mean for green threads?

2. Why are green threads cheaper than OS threads?

3. What does the runtime do when a green thread blocks on input?