EmbeddedPathashala · TLPI Series
Chapter 33: Threads — Further Details
Thread stacks, signals, process control, implementation models, LinuxThreads vs NPTL
What You Will Learn
Chapter 33 of The Linux Programming Interface builds on the POSIX Threads (Pthreads) foundation from Chapter 29 and explores the deeper, trickier corners of multithreaded Linux programming. You will understand how threads interact with the classic Unix signal model, what really happens when a multithreaded process calls fork() or exec(), how the kernel schedules threads (M:1, 1:1, M:N models), and the key differences between the two Linux thread libraries — LinuxThreads (legacy) and NPTL (modern).
Each tutorial file covers one focused topic with plain-English explanations, inline diagrams, real C code examples you can compile, and interview questions to test your understanding.
Key Concepts in This Chapter
Tutorial Files
File 01 · Index
Chapter Overview & Navigation
You are here. Start here to understand the structure of the series and the big picture of what Chapter 33 covers.
File 02 · Section 33.1
Thread Stacks
Every thread gets its own private stack. Learn the default sizes, why they matter, how to query the minimum, and how to resize stacks using pthread_attr_setstacksize(). Includes the virtual address space calculation for max thread count.
File 03 · Section 33.2
Threads and Signals
Signals and threads are a notoriously tricky combination. Learn what is process-wide vs per-thread in the signal model, how to safely use pthread_sigmask(), send signals with pthread_kill(), and the recommended sigwait() pattern for asynchronous signal handling.
File 04 · Section 33.3
Threads and Process Control
What happens when a multithreaded program calls fork(), exec(), or exit()? The answers are surprising and important. Covers the “only the calling thread survives fork” rule, mutex state inheritance dangers, and pthread_atfork() handlers.
File 05 · Section 33.4
Thread Implementation Models
A conceptual deep-dive into how threading libraries are built. Understand M:1 (user-level), 1:1 (kernel-level), and M:N (two-level) thread models. Understand what a Kernel Scheduling Entity (KSE) is and why Linux chose the 1:1 model for NPTL.
File 06 · Sections 33.5 + 33.6
Linux Pthreads: LinuxThreads vs NPTL
A detailed comparison of Linux’s two Pthreads implementations. Understand why LinuxThreads broke many POSIX rules (different PIDs per thread, broken signals), how NPTL fixed them using new kernel features like CLONE_THREAD and futexes, and how to detect and select the threading implementation at runtime.
Free Embedded Systems Education
EmbeddedPathashala is a free platform for students and freshers breaking into embedded Linux and systems programming.
