Book description
Computers are just as busy as the rest of us nowadays. They have lots of tasks to do at once, and need some cleverness to get them all done at the same time.That's why threads are seen more and more often as a new model for programming. Threads have been available for some time. The Mach operating system, the Distributed Computer Environment (DCE), and Windows NT all feature threads.One advantage of most UNIX implementations, as well as DCE, is that they conform to a recently ratified POSIX standard (originally 1003.4a, now 1003.1c), which allows your programs to be portable between them. POSIX threads are commonly known as pthreads, after the word that starts all the names of the function calls. The standard is supported by Solaris, OSF/1, AIX, and several other UNIX-based operating systems.The idea behind threads programming is to have multiple tasks running concurrently within the same program. They can share a single CPU as processes do, or take advantage of multiple CPUs when available. In either case, they provide a clean way to divide the tasks of a program while sharing data.A window interface can read input on dozens of different buttons, each responsible for a separate task. A network server has to accept simultaneous calls from many clients, providing each with reasonable response time. A multiprocessor runs a number-crunching program on several CPUs at once, combining the results when all are done. All these kinds of applications can benefit from threads.In this book you will learn not only what the pthread calls are, but when it is a good idea to use threads and how to make them efficient (which is the whole reason for using threads in the first place). The authors delves into performance issues, comparing threads to processes, contrasting kernel threads to user threads, and showing how to measure speed. He also describes in a simple, clear manner what all the advanced features are for, and how threads interact with the rest of the UNIX system.Topics include:
- Basic design techniques
- Mutexes, conditions, and specialized synchronization techniques
- Scheduling, priorities, and other real-time issues
- Cancellation
- UNIX libraries and re-entrant routines
- Signals
- Debugging tips
- Measuring performance
- Special considerations for the Distributed Computing Environment (DCE)
Publisher resources
Table of contents
- Pthreads Programming
- A Note Regarding Supplemental Files
- Examples
- Preface
-
1. Why Threads?
- What Are Pthreads?
- Potential Parallelism
- Specifying Potential Parallelism in a Concurrent Programming Environment
- Parallel vs. Concurrent Programming
- Synchronization
- Who Am I? Who Are You?
- Terminating Thread Execution
- Why Use Threads Over Processes?
- A Structured Programming Environment
- Choosing Which Applications to Thread
- 2. Designing Threaded Programs
-
3. Synchronizing Pthreads
- Selecting the Right Synchronization Tool
-
Mutex Variables
- Using Mutexes
- Error Detection and Return Values
- Using pthread_mutex_trylock
- When Other Tools Are Better
- Some Shortcomings of Mutexes
- Contention for a Mutex
- Example: Using Mutexes in a Linked List
- Complex Data Structures and Lock Granularity
- Requirements and Goals for Synchronization
- Access Patterns and Granularity
- Locking Hierarchies
- Sharing a Mutex Among Processes
- Condition Variables
- Reader/Writer Locks
- Synchronization in the ATM Server
- Thread Pools
-
4. Managing Pthreads
- Setting Thread Attributes
- The pthread_once Mechanism
- Keys: Using Thread-Specific Data
- Cancellation
- Scheduling Pthreads
- Mutex Scheduling Attributes
-
5. Pthreads and UNIX
- Threads and Signals
- Threadsafe Library Functions and System Calls
- Cancellation-Safe Library Functions and System Calls
- Thread-Blocking Library Functions and System Calls
- Threads and Process Management
- Multiprocessor Memory Synchronization
- 6. Practical Considerations
- A. Pthreads and DCE
- B. Pthreads Draft 4 vs. the Final Standard
- C. Pthreads Quick Reference
- D. About the Authors
- Index
- About the Authors
- Colophon
- Copyright
Product information
- Title: PThreads Programming
- Author(s):
- Release date: September 1996
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781449364748
You might also like
book
Programming with POSIX ® Threads
With this practical book, you will attain a solid understanding of threads and will discover how …
book
Mastering C++ Multithreading
Master multithreading and concurrent processing with C++ About This Book Delve into the fundamentals of multithreading …
book
Multicore and GPU Programming
Multicore and GPU Programming offers broad coverage of the key parallel computing skillsets: multicore CPU programming …
book
Embedded Programming with Modern C++ Cookbook
Explore various constraints and challenges that embedded developers encounter in their daily tasks and learn how …