Programming with POSIX Threads and over one million other books are available for Amazon Kindle. Learn more

Vous voulez voir cette page en français ? Cliquez ici.


or
Sign in to turn on 1-Click ordering.
or
Amazon Prime Free Trial required. Sign up when you check out. Learn More
More Buying Choices
Have one to sell? Sell yours here
Start reading Programming with POSIX Threads on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Programming with POSIX Threads [Paperback]

David R. Butenhof
4.2 out of 5 stars  See all reviews (18 customer reviews)
List Price: CDN$ 67.99
Price: CDN$ 42.83 & FREE Shipping. Details
You Save: CDN$ 25.16 (37%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Only 1 left in stock (more on the way).
Ships from and sold by Amazon.ca. Gift-wrap available.
Want it delivered Tuesday, April 22? Choose One-Day Shipping at checkout.

Formats

Amazon Price New from Used from
Kindle Edition CDN $40.69  
Paperback CDN $42.83  

Book Description

May 16 1997 0201633922 978-0201633924 1

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.


Customers Who Bought This Item Also Bought


Product Details


Product Description

From the Inside Flap

The White Rabbit put on his spectacles,
"Where shall I begin, please your Majesty?" he asked.
"Begin at the beginning," the King said, very gravely,
"and go on till you come to the end: then stop."

 ***-Lewis Carroll, Alice's Adventures in Wonderland


This book is about "threads" and how to use them. "Thread" is just a name for a basic software "thing" that can do work on a computer. A thread is smaller, faster, and more maneuverable than a traditional process. In fact, once threads have been added to an operating system, a "process" becomes just data--address space, files, and so forth--plus one or more threads that do something with all that data.

With threads, you can build applications that utilize system resources more efficiently, that are more friendly to users, that run blazingly fast on multiprocessors, and that may even be easier to maintain. To accomplish all this, you need only add some relatively simple function calls to your code, adjust to a new way of thinking about programming, and leap over a few yawning chasms. Reading this book carefully will, I hope, help you to accomplish all that without losing your sense of humor.

The threads model used in this book is commonly called "Pthreads," or "POSIX threads." Or, more formally (since you haven't yet been properly introduced), the POSIX 1003.1cn1995 standard. I'll give you a few other names later-but for now, "Pthreads" is all you need to worry about.

As I write this, Sun's Solaris, Digital's Digital UNIX, and SGI's IRIX already support Pthreads. The other major commercial UNIX operating systems will soon have Pthreads as well, maybe even by the time you read this, including IBM's AIX and Hewlett-Packard's HP-UX. Pthreads implementations are also available for Linux and other UNIX operating systems.

In the personal computer market, Microsoft's Win32 API (the primary programming interface to both Windows NT and Windows 95) supports threaded programming, as does IBM's OS/2. These threaded programming models are quite different from Pthreads, but the important first step toward using them productively is understanding concurrency, synchronization, and scheduling. The rest is (more or less) a matter of syntax and style, and an experienced thread programmer can adapt to any of these models.

The threaded model can be (and has been) applied with great success to a wide range of programming problems. Here are just a few:

  • Large scale, computationally intensive programs
  • High-performance application programs and library code that can take advantage of multiprocessor systems
  • Library code that can be used by threaded application programs
  • Realtime application programs and library code
  • Application programs and library code that perform I/O to slow external devices (such as networks and human beings).
Intended audience

This book assumes that you are an experienced programmer, familiar with developing code for an operating system in "the UNIX family" using the ANSI C language. I have tried not to assume that you have any experience with threads or other forms of asynchronous programming. The Introduction chapter provides a general overview of the terms and concepts you'll need for the rest of the book. If you don't want to read the Introduction first, that's fine, but if you ever feel like you're "missing something" you might try skipping back to get introduced.

Along the way you'll find examples and simple analogies for everything. In the end I hope that you'll be able to continue comfortably threading along on your own. Have fun, and "happy threading."

About the author

I have been involved in the Pthreads standard since it began, although I stayed at home for the first few meetings. I was finally forced to spend a grueling week in the avalanche-proof concrete bunker at the base of Snowbird ski resort in Utah, watching hard-working standards representatives from around the world wax their skis. This was very distracting, because I had expected a standards meeting to be a formal and stuffy environment. As a result of this misunderstanding, I was forced to rent ski equipment instead of using my own.

After the Pthreads standard went into balloting, I worked on additional thread synchronization interfaces and multiprocessor issues with several POSIX working groups. I also helped to define the Aspen threads extensions, which were fast-tracked into X/Open XSH5.

I have worked at Digital Equipment Corporation for (mumble, mumble) years, in various locations throughout Massachusetts and New Hampshire. I was one of the creators of Digital's own threading architecture, and I designed (and implemented much of) the Pthreads interfaces on Digital UNIX 4.0. I have been helping people develop and debug threaded code for more than eight years.

My unofficial motto is "Better Living Through Concurrency." Threads are not sliced bread, but then, we're programmers, not bakers, so we do what we can.

Acknowledgments

This is the part where I write the stuff that I'd like to see printed, and that my friends and coworkers want to see. You probably don't care, and I promise not to be annoyed if you skip over it-nbut if you're curious, by all means read on.

No project such as this book can truly be accomplished by a single person, despite the fact that only one name appears on the cover. I could have written a book about threads without any help-I know a great deal about threads, and I am at least reasonably competent at written communication. However, the result would not have been this book, and this book is better than that hypothetical work could possibly have been.

Thanks first and foremost to my manager Jean Fullerton, who gave me the time and encouragement to write this book on the job-and thanks to the rest of the DECthreads team who kept things going while I wrote, including Brian Keane, Webb Scales, Jacqueline Berg, Richard Love, Peter Portante, Brian Silver, Mark Simons, and Steve Johnson.

Thanks to Garret Swart who, while he was with Digital at the Systems Research Center, got us involved with POSIX. Thanks to Nawaf Bitar who worked with Garret to create, literally overnight, the first draft of what became Pthreads, and who became POSIX thread evangelist through the difficult period of getting everyone to understand just what the heck this threading thing was all about anyway. Without Garret, and especially Nawaf, Pthreads might not exist, and certainly wouldn't be as good as it is. (The lack of perfection is not their responsibility-that's the way life is.)

Thanks to everyone who contributed to the design of cma, Pthreads, UNIX98, and to the users of DCE threads and DECthreads, for all the help, thought-provoking discourse, and assorted skin-thickening exercises, including Andrew Birrell, Paul Borman, Bob Conti, Bill Cox, Jeff Denham, Peter Gilbert, Rick Greer, Mike Grier, Kevin Harris, Ken Hobday, Mike Jones, Steve Kleiman, Bob Knighten, Leslie Lamport, Doug Locke, Paula Long, Finnbarr P. Murphy, Bill Noyce, Simon Patience, Harold Seigel, Al Simons, Jim Woodward, and John Zolnowsky.

Many thanks to all those who patiently reviewed the drafts of this book (and even to those who didn't seem so patient at times). Brian Kernighan, Rich Stevens, Dave Brownell, Bill Gallmeister, Ilan Ginzburg, Will Morse, Bryan O'Sullivan, Bob Robillard, Dave Ruddock, Bil Lewis, and many others suggested or motivated improvements in structure and detail-and provided additional skin-thickening exercises to keep me in shape. Devang Shah and Bart Smaalders answered some Solaris questions, and Bryan O'Sullivan suggested what became the "bailing programmers" analogy.

Thanks to John Wait and Lana Langlois at Addison Wesley Longman, who waited with great patience as a first-time writer struggled to balance writing a book with engineering and consulting commitments. Thanks to Pamela Yee and Erin Sweeney, who managed the book's production process, and to all the team (many of whose names I'll never know), who helped. Thanks to my wife, Anne Lederhos, and our daughters Amy and Alyssa, for all the things for which any writers may thank their families, including support, tolerance, and just being there. And thanks to Charles Dodgson (Lewis Carroll), who wrote extensively about threaded programming (and nearly everything else) in his classic works Alice's Adventures in Wonderland, Through the Looking-Glass, and The Hunting of the Snark.

Dave Butenhof
Digital Equipment Corporation
110 Spit Brook Road, ZKO2-3/Q18
Nashua, NH 03062
butenhof@zko.dec.com
December 1996

0201633922P04062001

From the Back Cover

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.



0201633922B04062001

Inside This Book (Learn More)
Browse Sample Pages
Front Cover | Copyright | Table of Contents | Excerpt | Index
Search inside this book:

Customer Reviews

Most helpful customer reviews
3 of 3 people found the following review helpful
3.0 out of 5 stars Annoying, but probably no worse than the rest... Feb. 13 2001
Format:Paperback
This book has got what you want to know about pthreads. If that was all it had, and it had that in the right order, then it would be perfect. Instead, this is a very frustrating book to read.
Take 'mutexes' as an example. A useful explanation for a beginner might be as follows... (1) Where the word 'mutex' comes from (2) What a memory conflict is (3) How a mutex can avoid it (4) How it works (simplified) (5) Some good examples in programs
On page 6 we first meet a mutex in a bit about putchar - we turn 'putchar into a 'critical section' (unexplained) because 'putchar might lock a "putchar mutex" '.
Don't bother trying to understand it. Next paragraph, we find 'the correct solution is to associate the mutex with the stream', so it was a bad idea in the first place. Oh.
Two chapters later, on page 47, you get to know what a 'mutex' is. It's mutual exclusion using a special form of Edsger Dijkstra's semaphore, you dummy. Well, if you've read Edsger Dijkstra's 1968 paper, then you aren't likely to be reading this book, says I.
Confused? Keep going. Finally on page 90, there is a neat tabular description of one thread reading a variable before the other one has written it, and how you can stop this with a mutex. Clear and simple, this should have been on page 6. The following section (marked "You may want to skip this explanation...") then describes the sorts of problem you get with real hardware - surely a 'must read' if you are going to do this sort of stuff.
There is a noble tradition of giving a bad coding example in one chapter, so you can show how cleverly you can fix it in the next. Look at any Stroustrop book.
Read more ›
Was this review helpful to you?
1 of 1 people found the following review helpful
5.0 out of 5 stars The best book on the topic Oct. 25 2007
Format:Paperback
In my opinion, this book is better than Pthreads Programming because it goes way beyond just presenting the pthreads API. One critic I had on all the other multithreading books that I have read is that they are not covering issues with multithread programs on a SMP system. This book is actually discussing some of these issues on several pages! Beside this quality, it also covers high-level design patterns on how you can use threads such as pipelines, work crew and client/server. There is also a chapter showing how to program with thread cancellation and a section explaining how to create new synchronization objects from the primitives. This brings me to the only problem that I can think of this book: its age. It is not totally up to date. Learning how you can build new synchronization objects by itself is a very interesting exercise but the problem is that the new synchronization objects built are the barrier and the read/write lock which have been added to the pthreads API since the book publication. Also, except for a small section describing the futur of pthreads, the newest additions to the pthread API are not described.
Was this review helpful to you?
1.0 out of 5 stars A VERY frustrating book July 12 2007
Format:Paperback
You're better off with no book on threads then this one. I wasted soooo much time flipping through the book searching for explanations of things he mentioned off-handedly. A typical entry involves a convoluted and incomplete explanation of a new concept, followed by some example code that does nothing, followed by a rambling blurb that mentions the functions he used without even explaining all the arguments they take.

Take mutex_dynamic.c in his chapter on mutexes for example. He defines a data structure with a mutex inside it and then shows how you can allocate memory for his structure using malloc. The bulk of the code is actually devoted to checking for generic errors and passing them along to his custom error library as meaningless error messages. It's a 28-line program that demonstrates only two mutex pthread function calls: pthread_mutex_init(&someMutex,NULL) and pthread_mutex_destroy(&someMutex).

I'd rant more but Richard Kirk's review below already summed up everything else I hate about this book.
Was this review helpful to you?
2.0 out of 5 stars A frustrating book June 30 2003
Format:Paperback
Richard Kirk's review below is the most accurate. There are many annoying things about this book. In addition, I find the code suspicious. For example the examples he gives of mutexes is to associate them with data items, even though the vast majority of the time they're associated with executable code. The discussion of critical sections is basically non-existent with very little explanation of the equivalent functionality in Pthreads. His explanation of semaphores is very difficult to follow and far more complex than it need be. I found better and simpler tutorials on the Web.
Butenhof is at his best when explaining the deep stuff and the subtle aspects of parallel programming. If this is what you need, the book is great. But if you want someone to show you how to use Pthreads and enable you to get up to speed quickly, then you will find this book rather frustrating.
The absence of downloadable code is an additional frustration. I'd go with the books by Bil Lewis, which are more straightforward and he offers tons of downloadable examples.
Was this review helpful to you?
5.0 out of 5 stars Comprehensive and well-written April 21 2003
Format:Paperback
Butenhof covers all the details of programming the pthreads library. The book begins with a lucid and carefully presented discussion about the general concepts behind threading, such as locking, synchronization, race conditions, and data sharing. Threads can be a bit intimidating, but Butenhof's presentation makes threaded programming, and thinking about asynchronous design in general, much more manageable. His coverage of the library itself is very accurate and clear. The book helpfully contains a complete reference of the pthreads library. Another worthwhile feature is the discussion and implementation of several common design patterns for multithreaded programming. I have found myself modifying and reusing these patterns again and again. If you find yourself needing to program with the pthreads library, Butenhof will not lead you astray. Highly recommended.
Was this review helpful to you?
Want to see more reviews on this item?
Most recent customer reviews
5.0 out of 5 stars Reading Pleasure
I like to read books written that way.
To whom English is a foreign language an author's writing style
and choice of expression is sometimes the most important... Read more
Published on April 19 2002 by Psycho Chicken
4.0 out of 5 stars Not bad
I found this book very useful when learning about POSIX threads though the whole impression is a bit mixed. Read more
Published on Feb. 3 2002 by Anatoly Korzun
4.0 out of 5 stars Reference book for POSIX threads
This book is a fine reference for POSIX threads. It will teach you the why's and how's of thread programming with illustrative examples. Read more
Published on Oct. 18 2001 by Jorgen L Dahl
3.0 out of 5 stars Basically OK but not great
It's easy for me now - I compare all programming books I read to the definitive gem of technical writing - Stevens UNPv1. Read more
Published on March 14 2001 by Alexander L. Belikoff
5.0 out of 5 stars First Rate. Clear and authoritative
This book provides the clearest, most concise, and most authoritative treatment of POSIX threads that I have seen. Read more
Published on Nov. 18 2000 by Johnson M. Hart
4.0 out of 5 stars Really portable!
This book can make your job easier if you are coding in multi threaded programming environment. It is really helpful for the beginners like myself in this subject area. Read more
Published on Oct. 10 2000 by Jeremy
5.0 out of 5 stars Best threads book I've read
Well organized, very useful examples. The author annotates all the source code listings. Source code available on the Web.
Published on Aug. 14 2000 by "bobdempsey"
5.0 out of 5 stars Detailed and easy to understand
This book is great for beginners in Posix. It is detailed and clear. It gives careful explanation of the major Posix functions and complement them with full source codes which... Read more
Published on March 17 2000 by Vidius
Search Customer Reviews
Only search this product's reviews
ARRAY(0xb08bf978)

Look for similar items by category


Feedback