← Lessons

quiz vs the machine

Silver1100

Concurrency

The Green Threads and Fibers

How a runtime can schedule many lightweight tasks on top of a few real OS threads.

4 min read · intro · beat Silver to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. Who schedules green threads?

2. Why can a single blocking system call stall many green threads?