Contrasting POSIX API to the OS/2 and Win32 APIs gives the programmer a feeling for what kind of porting issues might be involved when writing to more than one of these libraries.
Describes context switching in detail.
Delves into the details of the various POSIX options and parameters.
Details and issues of the threads used are discussed.
References to other programs on the net are made.
Based on the best-selling Threads Primer, Multithreaded Programming with Pthreads gives you a solid understanding of Posix threads: what they are, how they work, when to use them, and how to optimize them.
It retains the clarity and humor of the Primer, but includes expanded comparisons to Win32 and OS/2 implementations. Code examples tested on all of the major UNIX platforms are featured along with detailed explanations of how and why they use threads.
In addition to scheduling, synchronization, signal handling, etc., special emphasis is placed on:
Background: Traditional Operating Systems. What Is a Thread? Kernel Interaction. The Value of Using Threads. What Kind of Programs to Thread? What About Shared Memory? Threads Standards. Performance.
Implementation vs. Specification. Thread Libraries. The Process Structure. Lightweight Processes. Solaris Multithreaded Model. System Calls. Signals.
Different Models of Kernel Scheduling. Thread Scheduling. Context Switching. When Should You Care About Scheduling?
Synchronization Issues. Synchronization Variables. A Stoppable Producer/Consumer Example.
Complex Locking Primitives. Other Synchronization Variables. Message Queues. Cross-Process Synchronization Variables. Initialization and Destruction. Synchronization Problems.
Thread-Specific Data. Global Variables, Constants, and Cheating.
What Cancellation Is. A Cancellation Example. Using Cancellation. Cancellation Safety. Simple Polling.
Signals in UNIX. The Solaris Implementation of Signal Handling. Don't Use Signal Handlers!
Attribute Objects. POSIX Thread Ids. Win32 Thread IDs and Thread Handles. Initializing Your Data: pthread_once(). POSIX Namespace Restrictions. Return Values and Error Reporting. Constants Comments. Pthread Futures. Pthread Extensions. Comparing the OS/2, Win32, and POSIX Libraries.
The Threads Library. Multithreaded Kernels. Are Libraries Safe? Stub Functions in libc. New Semantics for System Calls. Are Libraries Safe? Threads Debugger Interface. Mixing Solaris Pthreads and UI Threads. Comparisons of Different Implementations.
Making Libraries Safe and Hot. Manipulating Lists. Program Design.
C. C++. Java. Fortran. Ada. Pascal. Smalltalk. Lisp. Eiffel. Commercial Products. Public Pthreads Implementations.
Static Lock Analyzer. Using a Thread-Aware, Graphical Debugger. Debug Mutexes. Protocol. TNFview.
Optimization: Objectives and Objections. CPU Time, I/O Time, Contention, Etc. Limits on Speedup. Benchmarks and Repeatable Testing. The Lessons of NFS.
Types of Multiprocessors. Bus Architectures. Memory Systems.
Threads and Windows. Socket Server (Master/Slave Version). Socket Server (Producer/Consumer Version). Other Programs on the Web.
Threads Newsgroup. Code Examples. Vendor's Threads Pages. Threads Research. The SPILT Package for UI/POSIX Compatibility. Freeware Tools. Other Pointers. The Authors on the Net.
Threads Books. Related Books.
Function Descriptions. Pthread Functions. Pthread Attributes Objects. POSIX Realtime Scheduling. Mutexes. Mutex Attributes Objects. Condition Variables. Condition Variable Attributes Objects. Cancellation Functions. Thread-Specific Data Functions. Semaphores. Signal Functions. Stdio.
Today, there are three primary sets of multithreading (MT) libraries: the “standards-based” libraries (all of the UNIX( implementations and VMS, which are moving to POSIX), the OS/2( 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