Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 66 ยท Threads and Concurrency

User-Level and Kernel-Level Threads, Multithreading Models

Compare user-level and kernel-level threads and the many-to-one, one-to-one and many-to-many models, with a simulator showing why one blocking call can stall user threads.

Who knows about a thread: the application or the kernel? The answer gives two kinds of threads. User-level threads are created and scheduled by a library inside the process, and the kernel only sees the process. Kernel-level threads are created and scheduled by the OS itself. The relationship between the two kinds is the multithreading model, and it determines how well a program can use several cores and what happens when a thread makes a blocking call.

In this lesson you will compare the two kinds of threads, study the three classic mapping models, and run a simulation that shows the best-known weakness of user-level threads.

Who manages the thread?

User-level A library schedules them. Kernel does not know.
Kernel-level The OS schedules each thread.

Modern systems mostly use kernel-level threads, often with lightweight tasks on top.

1 / 2

User-level threads (ULT)

With ULTs, a thread library in user space keeps its own thread table and does its own scheduling, switching between threads by saving and restoring registers without any system call.

Advantages: very fast creation and switching (no kernel involvement), works on any OS, and the application can pick its own scheduling policy.

Disadvantages: the kernel sees only one execution unit, so if one thread makes a blocking system call (a disk or network read) the whole process blocks, and all the other user threads stop too. Also, all user threads of a process run on one core at a time: no parallelism.

Kernel-level threads (KLT)

Here the OS keeps a thread table and schedules each thread separately. Creating a thread is a system call.

Advantages: if one thread blocks, the kernel runs another thread of the same process; threads can run in parallel on different cores.

Disadvantages: creation and switching are slower (system calls and kernel data structures), and the kernel needs space for each thread.

Aspect User-level Kernel-level
Managed by Thread library Operating system
Switch cost Very low Higher
Blocking call Blocks all threads of the process Blocks only the calling thread
Multicore parallelism No Yes
OS support needed None Yes

Multithreading models

Many-to-one

Many user threads map to a single kernel thread. It is the pure ULT scheme and has all its flaws: one blocking call stops everyone, and there is no multicore use. Early thread libraries (such as the original Solaris green threads and GNU Portable Threads) worked this way.

One-to-one

Each user thread is backed by its own kernel thread. This gives true parallelism and independent blocking, at the cost of more kernel resources, so some systems limit the number of threads. Linux, Windows and modern macOS use this model, so pthread_create or std::thread creates a real kernel-schedulable thread.

Many-to-many

Many user threads are multiplexed onto a smaller or equal number of kernel threads. The user-level scheduler decides which user thread runs on each kernel thread, so you can create thousands of cheap threads and still use all cores. If one blocks, the kernel thread can run another. This is flexible but complex to implement. A variation, the two-level model, also lets a user thread be bound to one kernel thread. Modern runtimes revive this idea: Go goroutines, Java virtual threads, Erlang processes and Kotlin coroutines are all lightweight user-level tasks scheduled over a pool of OS threads.

flowchart TB
    subgraph M1["Many-to-one"]
      u1["U1"] --> k1["K1"]
      u2["U2"] --> k1
      u3["U3"] --> k1
    end
    subgraph O1["One-to-one"]
      u4["U1"] --> k2["K1"]
      u5["U2"] --> k3["K2"]
      u6["U3"] --> k4["K3"]
    end
    subgraph MM["Many-to-many"]
      u7["U1"] --> k5["K1"]
      u8["U2"] --> k5
      u9["U3"] --> k6["K2"]
      u10["U4"] --> k6
    end

U = user thread, K = kernel thread.

Simulating a blocking call

The simulation gives four threads the same job: compute for one tick, make a "disk read" of 3 ticks, compute for one more tick. In the many-to-one model, the kernel sees one thread, so while it waits for the disk nothing else can run. In the one-to-one model, other threads fill the gap. (A cooperative simulator with a single "core" is used for both so the comparison is only about the model.)

Python Blocking in many-to-one vs. one-to-one

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The one-to-one model finishes sooner because the CPU runs thread B's computation while thread A waits on the disk. This is the practical reason Linux and Windows use kernel threads for ordinary programs. User-level threading remains popular inside runtimes that avoid blocking calls (using non-blocking I/O) so one stalled thread never freezes the others.

Thread libraries

A thread library gives programmers an API to create and manage threads. The common ones are POSIX Pthreads (a specification, implemented as user-level or kernel-level), Windows threads, and the Java thread API, which uses whatever the host OS provides (and virtual threads on top, since Java 21). Another approach is implicit threading, where the runtime manages threads for you; see thread pools.

Mini-model: scheduling many tasks over a pool

The final demo captures the many-to-many idea: ten tasks are multiplexed over just two "kernel threads", and the order of execution shows how the pool absorbs them.

Python Ten tasks on two kernel threads

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In the many-to-one model, what happens when one user thread makes a blocking system call?

    There is only one kernel thread, so blocking it blocks every user thread mapped to it.
  2. 2. Which model do Linux and Windows use for ordinary threads?

    Each thread created by the program gets its own kernel-schedulable thread.
  3. 3. Which statement about user-level threads is true?

    The library switches threads without the kernel, which is fast, but the kernel sees only one schedulable unit.
  4. 4. Go goroutines and Java virtual threads are examples of which idea?

    They give cheap, numerous tasks while a scheduler spreads them across a few kernel threads.

Summary

  • User-level threads are managed by a library (fast, no kernel support, but blocking stalls the process and no multicore).
  • Kernel-level threads are managed by the OS (parallel, independent blocking, slower to create and switch).
  • Models: many-to-one, one-to-one (Linux, Windows) and many-to-many (modern lightweight runtimes).
  • Thread libraries (Pthreads, Windows threads, Java) hide these details behind an API.

Next: Benefits and Pitfalls of Multithreading