did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780136807292

Multithreaded Programming With Pthreads

by ; ;
  • ISBN13:

    9780136807292

  • ISBN10:

    0136807291

  • Edition: 1st
  • Format: Paperback
  • Copyright: 1997-12-09
  • Publisher: Prentice Hall
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $34.95

Summary

This book will give the UNIX and NT programmer a solid, basic understanding of threads -- and the powerful new POSIX Pthreads library.The book begins with an overview of the need for, and evolution of multithreading. Understand how threads are constructed, and how operating systems like Solaris(r) provide support for them. Learn the fundamentals of thread scheduling and synchronization, understanding the trade-offs involved in using synchronization variables. Learn how to dispose of (cancel) unwanted threads; and manage asynchronous events via signaling. The book includes detailed coverage of writing and compiling multithreaded programs, including sample applications, libraries, design choices, performance optimization and hardware considerations.For all experienced C, UNIX and NT programmers who need to understand the new Pthreads library.

Author Biography

BIL LEWIS, formerly with Sun Microsystems, Inc., now consults and teaches multithreaded programming. He is the co-author of Threads Primer: A Guide to Multithreaded Programming (Sun Microsystems Press/Prentice Hall).

DANIEL J. BERG is the Chief Technology Officer for Sun Microsystems' U.S. Reseller Channel. Mr. Berg has published papers and several books on Sun technologies, including Threads Primer (with Bil Lewis) and Advanced Techniques for Java Developers (Wiley).

Table of Contents

1 Introduction
1(6)
2 Concepts
7(26)
Background: Traditional Operating Systems
8(2)
What Is a Thread?
10(3)
Kernel Interaction
13(4)
The Value of Using Threads
17(7)
What Kind of Programs to Thread?
24(3)
What About Shared Memory?
27(1)
Threads Standards
27(1)
Performance
28(5)
3 Foundations
33(14)
Implementation vs. Specification
34(1)
Thread Libraries
34(1)
The Process Structure
35(2)
Lightweight Processes
37(3)
Solaris Multithreaded Model
40(1)
System Calls
40(3)
Signals
43(4)
4 Lifecycle
47(14)
Thread Lifecycle
48(13)
5 Scheduling
61(20)
Different Models of Kernel Scheduling
62(2)
Thread Scheduling
64(7)
Context Switching
71(9)
When Should You Care About Scheduling?
80(1)
6 Synchronization
81(24)
Synchronization Issues
82(2)
Synchronization Variables
84(17)
A Stoppable Producer/Consumer Example
101(4)
7 Complexities
105(24)
Complex Locking Primitives
106(10)
Other Synchronization Variables
116(3)
Message Queues
119(1)
Cross-Process Synchronization Variables
120(2)
Initialization and Destruction
122(1)
Synchronization Problems
123(6)
8 TSD
129(8)
Thread-Specific Data
130(5)
Global Variables, Contants, and Cheating
135(2)
9 Cancellation
137(20)
What Cancellation Is
138(4)
A Cancellation Example
142(6)
Using Cancellation
148(6)
Cancellation Safety
154(1)
Simple Polling
154(3)
10 Signals
157(12)
Signals in UNIX
158(3)
The Solaris Implementation of Signal Handling
161(2)
Don't Use Signal Handlers!
163(6)
11 Details
169(22)
Attribute Objects
170(7)
POSIX Thread IDs
177(2)
Win32 Thread IDs and Thread Handles
179(1)
Initializing Your Data: pthread_once()
179(2)
POSIX Namespace Restrictions
181(1)
Return Values and Error Reporting
181(3)
Constants Comments
184(2)
Pthread Futures
186(1)
Pthread Extensions
187(2)
Comparing the OS/2, Win32, and POSIX Libraries
189(2)
12 Libraries
191(16)
The Threads Library
192(1)
Multithreaded Kernels
192(2)
Are Libraries Safe?
194(7)
Stub Functions in libc
201(1)
New Semantics for System Calls
202(2)
Are Libraries Safe?
204(1)
Threads Debugger Interface
204(1)
Mixing Solaris Pthreads and UI Threads
205(1)
Comparisons of Different Implementations
205(2)
13 Design
207(24)
Making Libraries Safe and Hot
208(5)
Manipulating Lists
213(10)
Program Design
223(8)
14 Languages
231(14)
C
232(1)
C++
232(1)
Java
233(3)
Fortran
236(1)
Ada
236(1)
Pascal
237(1)
Smalltalk
237(1)
Lisp
237(1)
Eiffel
238(1)
Commercial Products
238(4)
Public Pthreads Implementations
242(3)
15 Tools
245(10)
Static Lock Analyzer
246(1)
Using a Thread-Aware, Graphical Debugger
246(3)
Debug Mutexes
249(2)
Proctool
251(1)
TNFview
251(4)
16 Performance
255(24)
Optimization: Objectives and Objections
256(3)
CPU Time, I/O Time, Contention, Etc
259(3)
Limits on Speedup
262(6)
Benchmarks and Repeatable Testing
268(7)
The Lessons of NFS
275(4)
17 Hardware
279(18)
Types of Multiprocessors
280(3)
Bus Architectures
283(10)
Memory Systems
293(4)
18 Examples
297(16)
Threads and Windows
298(6)
Socket Server (Master/Slave Version)
304(6)
Socket Server (Producer/Consumer Version)
310(2)
Other Programs on the Web
312(1)
Appendices
313(50)
A Internet
313(4)
Threads Newsgroup
313(1)
Code Examples
314(1)
Vendor's Threads Pages
314(1)
Threads Research
314(1)
The SPILT Package for UI/POSIX Compatibility
314(1)
Freeware Tools
315(1)
Other Pointers
315(1)
The Authors on the Net
315(2)
B Books
317(4)
Threads Books
317(2)
Related Books
319(2)
C Timings
321(4)
D Mistakes
325(6)
E APIs
331(32)
Function Descriptions
332(1)
Pthread Functions
333(3)
Pthread Attributes Objects
336(3)
POSIX Realtime Scheduling
339(3)
Mutexes
342(3)
Mutex Attributes Objects
345(2)
Condition Variables
347(3)
Condition Variable Attributes Objects
350(1)
Cancellation Functions
351(2)
Thread-Specific Data Functions
353(2)
Semaphores
355(4)
Signal Functions
359(2)
Stdio
361(2)
Glossary 363(14)
Index 377

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

Preface Today, there are three primary sets of multithreading (MT) libraries: the "standards-based" libraries (all of the UNIX#xA8; implementations and VMS, which are moving to POSIX), the OS/2#xA8; library, and the Win32 library. (The NT and OS/2 libraries are fairly similar, which should not be too surprising. NT did start life as OS/2, version 2, after all.) Although the APIs and implementations differ significantly, the fundamental concepts are the same. The ideas in this book are valid for all three; the details of the APIs differ. All the specific discussion in this book focuses on the POSIX multithreading model, with comparisons to OS/2 and Win32 throughout. A frank note about our motivation is in order here. We have slaved away for countless hours on this book because we''re propeller-heads who honestly believe that this technology is a superb thing and that the widespread use of it will make the world a better place for hackers like ourselves. Your motivations for writing MT programs? You can write your programs better and more easily, they''ll run faster, and you''ll get them to market more quickly, they''ll have fewer bugs, you''ll have happier programmers, customers, and higher sales. The only losers in this game are the competitors, who will lag behind you in application speed and quality. MT is here today. It will soon be ubiquitous. As a professional programmer, you have an obligation to understand this technology. It may or may not be appropriate for your current project, but you must be able to make that conclusion yourself. This book will give you what you need to make that decision. Welcome to the world of the future! Who Should Use This Book This book aims to give the programmer or technical manager a solid, basic understanding of threads--what they are, how they work, why they are useful, and some of the programming issues surrounding their use. As an introductory text, it does not attempt a deep, detailed analysis. (At present, there are no deep, detailed analyses!) After reading this book the reader should have a solid understanding of the fundamentals, be able to write credible, modestly complex, threaded programs and have the understanding necessary to analyze their own programs and determine the viability of threading them. This book is written with the experienced C/UNIX programmer in mind. A non-UNIX programmer will find a few of the details unfamiliar, but the concepts clear. A non-C programmer will find the code fragments and API descriptions mildly challenging, though possible to decipher, while the concepts should be clear. A technically minded nonprogrammer should be able to follow most of the concepts and understand the value of threads. A nontechnical person will not get much from this book. This book does not attempt to explain the usage of the Win32 or OS/2 APIs. It does contrast them to the POSIX API in order to give the POSIX programmer a feeling for what kind of porting issues might be involved when writing to more than one of these libraries. How This Book Is Organized Chapter 1, Introduction--In which we discuss the motivation for creating thread libraries, the advent of shared memory multiprocessors, and the interactions between threads and SMP machines. Chapter 2, Concepts--In which the reader is introduced to the basic concepts of multitasking operating systems and of multithreading as it compares to other programming paradigms. The reader is shown reasons why multithreading is a valuable addition to programming paradigms, and a number of examples of successful deployment are presented. Chapter 3, Foundations--In which we introduce to the underlying structures upon which threads are built, the construction of the thread itself, and the operating system support that allows an efficient implementation. Chapter 4, Lifecycle--In which the reader is treated to a comprehensive explanation of the intricacies in the life of a thread--birth, life, and death. Even death by vile cancellation. A small program which illustrates all of these stages concludes the chapter. Chapter 5, Scheduling--In which we explain the myriad details of the different scheduling models and the various alternative choices that could be made, describe context switching in detail, and delve into gruesome detail of the various POSIX options and parameters. There is a light at the end of the tunnel, however. Chapter 6, Synchronization--In which the reader is led on a hunt for the intimidating synchronization variable and discovers that it is not actually as frightening as had been thought. Programs illustrating the basic use of the POSIX primitives are shown. Chapter 7, Complexities--In which a series of more complex synchronization variables and options are presented and the trade-off between them and the simpler ones are discussed. Synchronization problems and techniques for dealing with them conclude the chapter. Chapter 8, TSD--In which an explanation of thread-specific data is provided, its use and some of the implementation details. We note a few places where use of TSD could be made more efficient and a few other optimizations that can be made. Chapter 9, Cancellation--In which we describe the acrimonious nature of some programs and how unwanted threads may be disposed of. The highly complex issues surrounding bounded time termination and program correctness are also covered. A simple conclusion is drawn. Chapter 10, Signals--In which we deal with the various aspects of handling asynchronous events in a multithreaded program. The definitions are given, alternative designs are discussed, and a program illustrating the most complex case is shown. Chapter 11, Details--In which the details of actually writing and compiling an MT program are reviewed. The defined constants are described and methods of dealing with errors are proposed. We note which vendors have made extensions to Pthreads, and where POSIX is headed. Chapter 12, Libraries--In which we explore a variety of operating systems issues that bear heavily upon the usability of the threads library in actual programs. We examine the status of library functions and the programming issues facing them. We look at some design alternatives for library functions. Chapter 13, Design--In which we explore some designs for programs and library functions. Making both programs and individual functions more concurrent is a major issue in the design of these functions. We look at a variety of code examples and the trade-offs between them. Chapter 14, Languages--In which the use of threads in various programming languages is considered and a few minor notes about special features and requirements are made. A number of public Pthreads libraries and some commercial products exist and are noted. Chapter 15, Tools--In which we consider the kinds of new tools that a reader would want when writing a threaded program. An overview of the Solaris tool set is given, as representative of what should be looked for. Chapter 16, Performance--In which we make things faster, look at general performance issues, political performance issues, and thread specific performance issues. We conclude with a discussion of the actual performance of multithreaded NFS. Chapter 17, Hardware--In which we look at the various designs for SMP machines (cache architectures, interconnect topologies, atomic instructions, invalidation techniques) and consider how those designs affect our programming decisions. Some optimization possibilities are looked at. Chapter 18, Examples--In which several

Rewards Program