Part 1 of 7 · 1 min read
Why this page comes third
In this module you will
- Tell a user-level thread from a kernel-level thread.
- Name the three mapping models (many-to-one, one-to-one, many-to-many) and say what each costs and gains.
- Show with code why a blocking call in a many-to-one library stops all threads.
- Say how Linux implements
pthread_createwithclone. - Show with a measurement that kernel threads run in parallel on several processors.
Page 2 used pthread_create as a black box. This page opens the box. The question is who keeps the records of a thread: the library inside the process, or the kernel itself (Level 1, page 2 described the kernel's records for processes). The answer decides whether two threads can run at the same time, and what happens when one of them waits for the disk. Page 4 then deals with writing safe code for threads, and page 6 uses the answers about parallelism. The main sources are "Operating System Concepts" (OSC), chapter 4, "Modern Operating Systems" (MOS), chapter 2, and "The Linux Programming Interface" (TLPI), chapter 29. All programs were compiled with gcc -Wall -Wextra and run on Linux.
About this example About this example
Real: The C programs, commands and outputs on this page were compiled with gcc -Wall -Wextra -pthread and run on a Linux test machine (2 processors, kernel 6.18, glibc 2.39).
Scripted: The worked traces use small numbers chosen so they can be followed by hand.
Not real: The page simplifies real systems. Actual kernels add more cases, limits and tuning than a short page can show.