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
UNIX libraries and re-entrant routines
Special considerations for the Distributed Computing Environment (DCE)
Chapter 1 Why Threads?
What Are Pthreads?
Specifying Potential Parallelism in a Concurrent Programming Environment
Parallel vs. Concurrent Programming
Who Am I? Who Are You?
Terminating Thread Execution
Why Use Threads Over Processes?
A Structured Programming Environment
Choosing Which Applications to Thread
Chapter 2 Designing Threaded Programs
Suitable Tasks for Threading
Buffering Data Between Threads
Some Common Problems
Example: An ATM Server
Example: A Matrix Multiplication Program
Chapter 3 Synchronizing Pthreads
Selecting the Right Synchronization Tool
Synchronization in the ATM Server
Chapter 4 Managing Pthreads
Setting Thread Attributes
The pthread_once Mechanism
Keys: Using Thread-Specific Data
Mutex Scheduling Attributes
Chapter 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
Dick Buttlar is a consulting writer in the UNIX Engineering Group at Digital Equipment Corporation, where he recently completed his stint as project leader for the Digital UNIX cluster documentation. He specializes in programming documentation -- both user-level and kernel -- and, in a former life, wrote the device driver documentation for the VMS operating system. A few years ago, he managed the initial planning of the corporate- wide documentation effort for Digital's Alpha processor. He's worked for Wang Laboratories, Recal/Redac, North American Technologies, and the American Trial Lawyers Association, among other places. He has a B.A. in English from Boston College and an M.A. in English from the University of Wisconsin at Madison.
Brad Nichols is a free-lance do-anything-computerish-for-a-buck kind of guy who works out of Milford, NH. He earned a Bachelor of Science degree in mechanical engineering from the University of New Hampshire in 1985 and a Master of Science degree from Worcester Polytechnic Institute (WPI) in 1991. He started his computer career working on very hard hardware (fuel pumps and valves). He worked his way up through the hardware layers into software on projects involving embedded avionics systems at Textron Lycomming and United Technologies Hamilton Standard Division. Brad left these jobs to learn more about AI at WPI, but instead caught the Mach fever, and was introduced to threads programming in UNIX. While at WPI he also worked on an OSF/1 performance project for the Open Software Foundation (OSF). After attending WPI, Brad taught training seminars to software developers on the Mach kernel interfaces. He then joined Digital Equipment Corporation to work on the port of the OSF's Distributed Computing Environment's Distributed File System (OSFDCEDFSDU for short) to Digital UNIX. Now, Brad is once again on his own and spends most of his time teaching software engineers about technologies with much shorter acronyms -- such as Pthreads.
Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal featured on the cover of Pthreads Programming is a silkworm. Silkworms produce silk when they secrete a fine, strong filament while spinning their cocoons. According to legend, the Empress Ling-chi discovered how to unwind the filament approximately 3000 years ago B.C., and thus produced the world's first silk fabric. Silkworms survive exclusively on certain strains of mulberry leaves. The cultivated silkworm no longer exists in the wild. Although silkworms have been cultivated on a relatively small scale elsewhere, few places have both the warm climate and the abundance of mulberry trees that silkworms require, and so Asia, specifically China, continues to be the main producer of silk. UNIX and its attendant programs can be unruly beasts. Nutshell Handbooks help you tame them.Hanna Dyer designed the cover of this book, based on a series design by Edie Freedman. The image is a 19th-century engraving from the Dover Pictorial Archive. The cover layout was produced with Quark XPress 3.3 using the ITC Garamond font.The inside layout was designed by Edie Freedman, Jennifer Niederst, and Nancy Priest. Text was prepared by Erik Ray in SGML DocBook 2.4 DTD. The print version of this book was created by translating the SGML source into a set of gtroff macros using a filter developed at ORA by Norman Walsh. Steve Talbott designed and wrote the underlying macro set on the basis of the GNU troff -gs macros; Lenny Muellner adapted them to SGML and implemented the book design. The GNU groff text formatter version 1.09 was used to generate PostScript output. The text and heading fonts are ITC Garamond Light and Garamond Book. The illustrations that appear in the book were created in Macromedia Freehand 5.0 by Chris Reilley. This colophon was written by Clairemarie Fisher O'Leary
Let me preface this by saying this book was not written for someone who just learned their first Hello World program. It assumes you are a reasonably proficient C programmer already and want to learn Pthreads.
The book walks through all the major Pthreads topics in a style that focuses on how to transform your single threaded program into one that can take advantage of Pthreads. This might sound easy and straight forward. However, as is pointed out in the book, the process sometimes requires substantial redesign of your program and workflow. As the previous commenter found out, you can not bring your preconceived notion of how threaded programs work to Pthreads and expect the technology to compensate.
I'd like to give this book 5 stars but can't for three reasons: 1. The code examples are littered with typos. Any programmer worth his oats can debug them in just a few minutes; which is what the technical editor should have done before publishing the book. 2. I have the 2nd edition, which it seems they fixed some of the errors from #1, but also added more errors, and expanded the code examples to include some of the comments from the text. The text explains that some of the examples could be expanded for more functionality, performance, or other requirements; it would have been really nice if more of these expansions were included in the 2nd edition. Also, the text notes deficiencies in the code from the 1st edition; they were fixed for the 2nd edition, but the 2nd edition text was not changed to reflect this. 3. There is more than one place where the status of a thread is not explicitly spelled out by the text. Typically you can guess what the thread would be doing, but sometimes it is not obvious. This is again a place where a good C programmer will have insights and understanding that a beginner will not. The code examples include constructs to account for the various state artifacts, though without explanation.
I would still highly recommend this book for any semi-experienced programmer who wants to know more about Pthreads. I would not recommend this book alone for someone trying to learn C programming and Pthreads all at once.
Bottom Line Yes, I would recommend this to a friend
The book was OK when I first read it. However, I think that it lacks necessary detail about thread synchronization. The mutex/condition variable example using inc_counter and watch_count wouldn't work. Frankly, I've found that there are a lot of problems one will run into if they try to develop an app after having read this book. No attempt is made to discuss what happens when a thread waiting on a condition variable doesn't get to run even though it has been signalled (using pthread_cond_signal). The gloss over of pipelining was particularly annoying to me since I really wanted to implement a working pipeline using pthreads, but haven't been able to due to the problem mentioned above. I could be missing something, but the point of the book is to ensure (at least on some level) that I'm not...