EmbeddedRelated.com
Books

Programming with POSIX Threads (Addison-Wesley Professional Computing Series)

Butenhof, David 1997

With this practical book, you will attain a solid understanding of threads and will discover how to put this powerful mode of programming to work in real-world applications.

The primary advantage of threaded programming is that it enables your applications to accomplish more than one task at the same time by using the number-crunching power of multiprocessor parallelism and by automatically exploiting I/O concurrency in your code, even on a single processor machine. The result: applications that are faster, more responsive to users, and often easier to maintain. Threaded programming is particularly well suited to network programming where it helps alleviate the bottleneck of slow network I/O.

 

This book offers an in-depth description of the IEEE operating system interface standard, POSIXAE (Portable Operating System Interface) threads, commonly called Pthreads. Written for experienced C programmers, but assuming no previous knowledge of threads, the book explains basic concepts such as asynchronous programming, the lifecycle of a thread, and synchronization. You then move to more advanced topics such as attributes objects, thread-specific data, and realtime scheduling. An entire chapter is devoted to "real code," with a look at barriers, read/write locks, the work queue manager, and how to utilize existing libraries. In addition, the book tackles one of the thorniest problems faced by thread programmers-debugging-with valuable suggestions on how to avoid code errors and performance problems from the outset.

 

Numerous annotated examples are used to illustrate real-world concepts. A Pthreads mini-reference and a look at future standardization are also included.


Why Read This Book

You should read this book if you need a clear, authoritative treatment of pthreads and multithreaded design: it teaches the POSIX Threads API, common synchronization patterns, and practical techniques for writing correct, maintainable concurrent programs. The explanations and examples help you reason about race conditions, deadlock, and thread lifecycle so you can apply the same principles on embedded Linux and POSIX-capable RTOSes.

Who Will Benefit

Embedded and systems engineers (firmware developers, embedded Linux developers, RTOS integrators) who need to write or debug multithreaded code and design thread-safe system components.

Level: Intermediate — Prerequisites: Working knowledge of C and basic UNIX concepts (processes, signals, file I/O); familiarity with basic concurrency concepts (race, critical section) is helpful.

Get This Book

Key Takeaways

  • Use the POSIX pthreads API to create, join, detach, and control threads
  • Apply mutexes, condition variables, read-write locks, and other primitives to synchronize threads safely
  • Design thread-safe libraries and avoid common pitfalls such as deadlock, starvation, and race conditions
  • Manage thread lifetime and cancellation correctly, including cleanup handlers and resource ownership
  • Tune thread attributes and scheduling policies for responsiveness and real-time behavior on POSIX systems
  • Debug and test multithreaded programs using practical strategies to reproduce and diagnose concurrency bugs

Topics Covered

  1. Introduction to Threaded Programming and POSIX Threads
  2. Thread Creation, Termination, and Attributes
  3. Mutexes and Simple Synchronization
  4. Condition Variables and Complex Synchronization Patterns
  5. Read–Write Locks and Other Synchronization Primitives
  6. Thread-Specific Data and Reentrancy
  7. Thread Cancellation, Cleanup, and Robustness
  8. Signals, Threads, and Asynchronous Events
  9. Scheduling, Priorities, and Real-Time Extensions
  10. Design Patterns for Multithreaded Programs
  11. Debugging and Testing Multithreaded Applications
  12. Portability, Performance, and Best Practices
  13. Appendices: API Reference and Example Programs

Languages, Platforms & Tools

CPOSIX-compliant UNIX/LinuxEmbedded LinuxPOSIX-capable RTOSes (RTEMS, NuttX, QNX, etc.)pthreads library (libpthread)gcc/clanggdbvalgrind/helgrindstrace/ltrace

How It Compares

More focused on pthreads than Stevens' UNIX texts and older than Kerrisk's The Linux Programming Interface; compared with Nichols/Buttlar/Farrell's Pthreads book, Butenhof is often praised for clearer exposition and practical design guidance.

Related Books

Bryant, Randal, O'Hallaron,...