Part 2 of 7 · 2 min read
Two kinds
Think of it this way. A theatre has actors on stage and a director who decides who is on stage at any moment. If the actors arrange their turns by themselves and the director only sees "one troupe", the troupe manages its own scheduling. If the director knows every actor by name and assigns each one a place, the director controls the scheduling. The analogy stops in one place: a real troupe could pause for lunch together, but a thread library has no such control over the kernel.
In plain words: A user-level thread is a thread that a library inside the process creates and schedules. The kernel does not know it exists: to the kernel there is one process with one line of execution. Creating and switching such threads needs no system call, because it is only changes to data structures in the process's own memory.
A kernel-level thread is a thread that the kernel knows and schedules. Each has a record in the kernel (a thread version of the PCB of Level 1, page 2), and the kernel decides on which processor it runs.
User-level thread and kernel-level thread
A user-level thread is a thread whose creation, switching and scheduling are done by a thread library in user mode, so the kernel sees only the single process that contains it. A kernel-level thread is a thread that the kernel itself creates, tracks and schedules, so the kernel can run different threads of one process on different processors.
Example: a library that switches between its own threads with plain function calls uses user-level threads; the threads made by pthread_create on Linux are kernel-level threads.
Check yourself: 1. Who schedules a user-level thread? 2. Does creating a user-level thread need a system call? 3. How many lines of execution does the kernel see in a process of 10 user-level threads?