POSIX threads, or pthreads, allow multiple tasks to run 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. This book thoroughly covers the POSIX threads standard, which is supported by the Distributed Computer Environment (DCE), as well as Solaris, OSF/1, AIX, and several other UNIX-based operating systems. 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 clearly describes all the advanced features and how threads interact with the rest of the UNIX system.
Author(s): Bradford Nichols, Dick Buttlar, Jacqueline Proulx Farrell
Series: O'Reilly Nutshell
Edition: 1
Publisher: O'Reilly Media
Year: 1996
Language: English
Pages: 195
Pthreads Programming......Page 1
Table of Contents......Page 2
Preface......Page 5
Example Programs......Page 7
Typographical Conventions......Page 8
Acknowledgments......Page 9
Appendix B - Pthreads Draft 4 vs. the Final Standard......Page 0
Overview......Page 10
What Are Pthreads?......Page 13
Potential Parallelism......Page 14
Specifying Potential Parallelism in a Concurrent Programming Environment......Page 16
Parallel vs. Concurrent Programming......Page 21
Synchronization......Page 22
Who Am I? Who Are You?......Page 25
Terminating Thread Execution......Page 26
Why Use Threads Over Processes?......Page 29
A Structured Programming Environment......Page 30
Choosing Which Applications to Thread......Page 31
Overview......Page 32
Suitable Tasks for Threading......Page 33
Models......Page 35
Buffering Data Between Threads......Page 40
Some Common Problems......Page 42
Performance......Page 43
Example: An ATM Server......Page 44
Example: A Matrix Multiplication Program......Page 51
Overview......Page 55
Selecting the Right Synchronization Tool......Page 57
Mutex Variables......Page 59
Condition Variables......Page 68
Reader/Writer Locks......Page 71
Synchronization in the ATM Server......Page 75
Thread Pools......Page 81
Overview......Page 88
Setting Thread Attributes......Page 90
The pthread_once Mechanism......Page 93
Keys: Using Thread-Specific Data......Page 96
Cancellation......Page 101
Scheduling Pthreads......Page 110
Mutex Scheduling Attributes......Page 118
Overview......Page 123
Threads and Signals......Page 125
Threadsafe Library Functions and System Calls......Page 132
Cancellation-Safe Library Functions and System Calls......Page 137
Thread-Blocking Library Functions and System Calls......Page 139
Threads and Process Management......Page 140
Multiprocessor Memory Synchronization......Page 143
Overview......Page 144
Understanding Pthreads Implementation......Page 145
Debugging......Page 150
Performance......Page 157
Conclusion......Page 168
Appendix A - Pthreads and DCE......Page 169
What Does the DCE Programmer Have to Do?......Page 171
Example: The ATM as a DCE Server......Page 172
Detaching a Thread......Page 175
Mutex Variables......Page 176
Condition Variables......Page 177
Thread Attributes......Page 178
The pthread_once Function......Page 179
Keys......Page 180
Cancellation......Page 181
Scheduling......Page 182
Signals......Page 183
Threadsafe System Interfaces......Page 184
Error Reporting......Page 185
System Interfaces and Cancellation-Safety......Page 186
Process-Blocking Calls......Page 187
Process Management......Page 188
Appendix C - Pthreads Quick Reference......Page 189