The idea: who maps user threads to kernel threads?
A program asks for threads. Something must run those user threads on the CPU, and only the kernel can put work on a core: it schedules kernel threads. A threading model says how many kernel threads carry the user threads. There are three: many-to-one (N:1, all user threads on one kernel thread), one-to-one (1:1, one kernel thread each) and many-to-many (M:N, many user threads on a few kernel threads). The canvas runs the same user threads in all three models on 2 cores, one tick per step.
Many-to-one (N:1)
A thread library in user space keeps the user threads, their stacks and a run queue. Switching between them is a function call that saves and loads registers, with no system call, so it is cheap. But the kernel sees one thread, K1. It can run K1 on only one core, so the second core is never used: 4 threads of 3 ticks each take 12 ticks, while the other models take 6 (Demo: 4 CPU-bound threads on 2 cores). Worse, when the running user thread calls a blocking system call such as read() on a file, K1 sleeps in the kernel. The library is part of K1, so it cannot run anyone else: the whole process waits. In Demo: one blocking read() stalls many-to-one, a 4-tick read leaves the process with nothing running for 4 ticks and it ends at t = 15. Early Java "green threads" on Solaris and GNU Pth worked this way.
Libraries worked around the stall with non-blocking I/O: a socket read becomes "try, and if no data, park this user thread and ask poll() later". Then K1 keeps running the others (Demo: a socket wait: t = 11 instead of 15). Files, page faults and most other system calls have no such path.
One-to-one (1:1)
Every user thread is a kernel thread. pthread_create on Linux (NPTL) calls clone(), Windows has CreateThread, and a Java platform thread is one of these. The kernel schedules them on every core, and a blocking call puts only that one thread to sleep. That is why Linux, Windows and the JVM all moved to 1:1. The price is one kernel thread, kernel stack and scheduler entry per user thread, and every switch goes through the kernel: 6 user threads need 6 kernel threads (Demo: 6 threads, 2 file reads). The cost of a kernel thread and of its switch is on Threads vs Goroutines and Linux Context Switch; how threads share one address space is on Process vs Thread.
Many-to-many (M:N)
A runtime keeps the user threads in its own run queue, as N:1 does, but runs them on a few kernel threads, usually one per core. Switches stay in user space and both cores work, so it matches 1:1 on CPU work with 2 kernel threads instead of 4. The hard part is a blocking call. The kernel thread under the blocked user thread sleeps with it. If the runtime keeps exactly 2 kernel threads, a core idles until the read returns: in Demo: M:N with no spare kernel thread it ends at t = 8, not 6. So real M:N runtimes notice the block and start (or wake) a spare kernel thread for the free core: 3 kernel threads, done at t = 6. If every thread blocks at the same time, M:N needs as many kernel threads as 1:1 (Demo: every thread reads a file: 4 and 4).
Where Go and Java virtual threads fit
Both are M:N. Go runs goroutines on GOMAXPROCS threads; when a goroutine enters a blocking system call, sysmon hands its P to another thread (the handoff shown here), and a goroutine waiting on a socket parks on the netpoller and holds no thread (The Go Scheduler). Java 21 virtual threads run on a pool of carrier threads, one per core; a virtual thread that waits on a socket or a ReentrantLock unmounts and frees its carrier, while a blocking file read temporarily adds a carrier, much like the handoff (From a Java Thread to a CPU Core). Demo: a socket wait shows the cheap case: 2 kernel threads for 4 user threads, done at t = 6.
| Model | Kernel threads | Both cores? | One blocking read() | Examples |
|---|---|---|---|---|
| N:1 | 1 | ✗ one core | ✗ whole process waits | Green threads, GNU Pth |
| 1:1 | one per user thread | ✓ | ✓ only that thread waits | Linux NPTL, Windows, Java platform threads |
| M:N | about one per core, plus one per blocked call | ✓ | ✓ if the runtime adds a kernel thread | Go, Java virtual threads, Erlang |
Common mistakes
- "User threads give parallelism." Only kernel threads run on cores. N:1 has one, so it never runs two things at once.
- "M:N never blocks." A blocking system call still blocks a kernel thread; the runtime has to add one to keep the cores busy.
- "1:1 is slow." Kernel switches cost microseconds, which matters only with many thousands of threads or very frequent hand-offs.
What the page leaves out
Every scheduler here is first-come first-served and never preempts, and one tick is one unit of work, so switch costs are not counted. Real kernels preempt on a timer and on wake-up, and Go preempts a long-running goroutine after 10 ms. The page leaves out scheduler activations (the kernel upcall that early M:N designs on Solaris and NetBSD used to learn about blocks), Solaris lightweight processes, thread-local storage, signals and the two-level model that lets some threads be bound 1:1 inside an M:N runtime.