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.

Three panels. Many-to-one: user threads U1 to U4 in user space all point through a thread library to one kernel thread K1, which uses only core 0. One-to-one: U1 to U4 each point straight to their own kernel thread K1 to K4, scheduled on cores 0 and 1. Many-to-many: U1 to U4 go through a runtime onto two kernel threads K1 and K2, one per core.
The kernel only sees the kernel threads: one in N:1, one per user thread in 1:1, a few in M:N.

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).

Two timelines of 8 ticks for the same workload, where U1 runs 1 tick, then reads a file for 4 ticks. Many-to-one: core 0 runs U1, then shows 4 red stall ticks, then U1 and U2; core 1 is empty. Many-to-many with handoff: core 0 runs U1, then U3 on a new kernel thread K3, while core 1 keeps running U2 and U4; both are busy.
A blocking read() stops the only kernel thread in N:1; an M:N runtime hands the free core to a spare kernel thread.

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.

ModelKernel threadsBoth cores?One blocking read()Examples
N:11✗ one core✗ whole process waitsGreen threads, GNU Pth
1:1one per user thread✓✓ only that thread waitsLinux NPTL, Windows, Java platform threads
M:Nabout one per core, plus one per blocked call✓✓ if the runtime adds a kernel threadGo, 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.

On the mind map

Open the Operating Systems mind mapOperatingSystemsBoot and program start: from power on to main()Boot and program startProcesses and the kernel: how user code talks to the kernelProcesses and the kernelInterrupts and devices: hardware interrupts the CPUInterrupts and devicesScheduling and deadlock: who runs next, who gets whatScheduling and deadlockVirtual memory: every address is translatedVirtual memoryPhysical memory: who gets which bytes of RAMPhysical memoryFiles and storage: from open() down to the diskFiles and storageDisks and RAID: blocks down to platter or flashDisks and RAIDIsolation and security: limit what a process can doIsolation and securitySystem callSystem callsyscall instruction enters kernel modeProcess lifecycleProcess lifecycleexit leaves a zombie until parent waitsProcess vs threadProcess vs threadfork copies the address space, threads shareThreading models N:1 1:1 M:NN:1 blocks all on read(); M:N adds a threadShell pipelineShell pipelinepipe, fork, dup2 onto fd 0 and 1, execveSignal deliverySignal deliveryruns the handler on return to user spacestrace and gdbstrace and gdbptrace stops the child at each syscallTTY and job controlTTY and job controlline discipline turns Ctrl-C into SIGINTIPC: pipes, shm, queuesIPC: pipes, shm, queuesCopy through kernel vs share one pageMonolithic vs microkernelMonolithic vs microkernelOne call vs messages to server tasksOpen the Operating Systems mind mapOperating Systemshow user code talks to the kernelProcesses and the kernelSystem callSystem callsyscall instruction enters kernel modeProcess lifecycleProcess lifecycleexit leaves a zombie until parent waitsProcess vs threadProcess vs threadfork copies the address space, threads shareThreading models N:1 1:1 M:NN:1 blocks all on read(); M:N adds a threadShell pipelineShell pipelinepipe, fork, dup2 onto fd 0 and 1, execveSignal deliverySignal deliveryruns the handler on return to user spacestrace and gdbstrace and gdbptrace stops the child at each syscallTTY and job controlTTY and job controlline discipline turns Ctrl-C into SIGINTIPC: pipes, shm, queuesIPC: pipes, shm, queuesCopy through kernel vs share one pageMonolithic vs microkernelMonolithic vs microkernelOne call vs messages to server tasks
This page on the Operating Systems mind map · 64 pages in 9 branches · open it to see the whole map and test yourself in recall mode.