Threads are a powerful tool that allow programmers to improve their performance and structure of applications and utilize all the power of today's high performance computer. This book provides programmer's with a multithreaded programming learning tool, teaching tool, and reference all in one. The accompanying CD-ROM includes all code examples in the book.
"synopsis" may belong to another edition of this title.
Understand multithreading, the next dimension in high-performance computing. Thread Time is the easiest programmer's guide to the important new multi-threading techniques that are increasingly important in Windows NT/95, UNIX, POSIX, and other application development. Each concept in the book is illustrated with a picture, making this an exceptionally easy-to-understand book. The book introduces the process model, the thread model, and basic thread management functions. Learn how to synchronize and schedule threads. In a Programming Guidelines chapter, learn the basic do's and don'ts of multithreaded programming. The book includes extensive examples, exercises and references, including manual pages, debugging advice, and a CD-ROM loaded with practical information. This book is an effective introduction to multithreading for both professional programmers and students.From the Inside Flap:
Although threads have been around for decades, the use of threads on UNIXâ systems only started to become popular in the early 1990s. During this time, multiprocessor systems, client/server applications, and graphical user interfaces (GUIs) were making their way into the UNIX mainstream. Into this new era for UNIX, threads brought many benefits, but the most important was (and still is) performance. A multithreaded program can achieve significant performance gains through concurrent and/or parallel thread execution.
Concurrent thread execution means that two or more threads are in progress at the same time. If one thread blocks for some reason, another thread from the same program can execute in its place. This feature is especially relevant for cli- ent/server, GUI-based, and general I/O-bound applications. Parallelism occurs when two or more threads execute simultaneously across multiple processors. Parallelism exploits the processing power of multiprocessor systems and is espe- cially useful for compute-bound applications. Yet, threads are not a panacea. For example, thread management carries with it a certain amount of overhead. Thus, in order for a program to achieve a net performance gain, the concurrency or parallelism benefit must outweigh the thread management overhead liability. Fortunately, many applications can use threads to achieve significant perfor- mance gains.
This book teaches the application of multithreaded programming with the instruction, examples, and reference material needed to exploit this important software technology. Thread Time is primarily designed to be a practical guide for programming with POSIX.1c threads (also known as Pthreads). The Pthreads interfaces are presented and explained in detail. Code examples are provided, both in this book and on CD-ROM, that show how the interfaces are used. Guidelines teach you when to use threads, how to use them, how to avoid problems, and how to solve problems when they arise.
Thread Time may be suitable as a textbook in an advanced undergraduate or first-year graduate computer science curriculum. Clear objectives are provided at the beginning of each chapter, and exercises that help reinforce your knowl- edge of the technology are provided at the end of each chapter. The code exam- ples in this book are written in the C programming language.
Chapter Organization and Descriptions.
Although this has not been done explicitly, this book can be divided into five parts: Foundational Information, Pthreads Interfaces and Their Use, Program- ming with Threads, Advanced Topics, and Reference Material. Depending on your needs, you may wish to skip to a particular part or chapter.
1. Foundational Information.
Chapter 1: The Process Model chapter provides a foundation for understand- ing the benefits of threads. Herein, we present an overview of two areas: (1) the single-threaded process and (2) the process management portion of the UNIX operating system. At the end of this chapter, we draw a few conclusions about the limitations of single-threaded programming. Definitions for the Process Model, a process, and a thread are found in this chapter.
Chapter 2: The Thread Model chapter builds a foundation for programming with threads. Presented are several attributes of programs suitable for threads, several benefits of threads, and a high-level overview of three Thread Model operating systems. A number of essential definitions and concepts are provided in this chapter.
Chapter 3: The Introduction to POSIX chapter provides a brief introduction to the structure of POSIX and teaches you how to verify which POSIX thread functionality is supported on your system.
2. Pthreads Interfaces and Their Use.
Chapter 4: This chapter presents the Basic Thread Management interfaces and explains how they are used. These interfaces allow you to create, terminate, and synchronize threads. Specialized attributes are also available for creating threads with unique characteristics.
Chapter 5: The programmer assumes more responsibility when programming with threads. Thread operations must occur in the correct order, access to shared objects must be coordinated, and all threads must work together to achieve the desired result. Several mechanisms are available to coordinate, or synchronize, threads within a program. The Thread Synchronization chapter explains how to use these mechanisms.
Chapter 6: To accommodate varying needs, the scheduling policy and priority of POSIX.1c threads can be programmatically controlled. This chapter presents the Thread Scheduling interfaces, explains how they are used, and describes how threads compete for processor time.
Chapter 7: When a single-threaded process receives a signal, the default action is to terminate the process unless a signal handler has been installed. If a signal handler is invoked, program execution is interrupted. In a multithreaded pro- gram, signal handling is more flexible. A signal can be handled by a single thread within the program, allowing other threads to continue execution. The Threads and Signals chapter presents the Pthreads signal interfaces and explains how they are used.
Chapter 8: When programming with threads, it is often necessary to terminate a thread within the application. Signals appear to provide the most logical means to accomplish thread termination. However, signals have two major draw- backs: (1) if a signal causes a thread to terminate, the entire process terminates and (2) if POSIX allowed a signal to cause thread termination (and not process termination), mutexes and other resources acquired by terminated threads would never be released. The latter case could lead to deadlock. This chapter pre- sents the Thread Cancellation interfaces, explains the concept of thread can- cellation, and explains how resources are released when a thread is canceled.
Chapter 9: When a multithreaded program is written, a determination must be made as to how global data will be shared among the threads in the process. There are two choices: (1) a global data variable can be process shared and pro- tected with synchronization primitives; or (2) a global data variable can be spe- cific to each thread. In the second case, Thread-Specific Data is employed and synchronization is not required. This chapter presents the thread-specific data interfaces and explains how they are used.
Chapter 10: The HP-UX system includes several Thread Extensions, such as read-write locks, enhanced MxN Model scheduling control, processor affinity, and additional mutex types. Many of these features are thread extensions pro- vided by the X/Open Portability Guide. Some of these features are provided only by Hewlett-Packard and may not be portable. Nevertheless, all of these are pow- erful features that can enhance multithreaded programs.
Chapter 11: The Thread F/X (Effects) chapter discusses the behavior of com- mon library functions when they are used in multithreaded programs. For exam- ple, what happens when a thread calls fork? If a thread locks a file, will other threads in the same program still have access? Are there performance or porta- bility considerations when common library functions are used in multithreaded programs? Questions such as these are answered in this chapter.
3. Programming with Threads.
Chapter 12: The Writing Thread-Safe Code chapter defines thread-safing terminology and then describes several important facets of writing thread-safe code. At the end of this chapter, we provide a preflight checklist for designing thread-safe libraries.
Chapter 13: The Programming Guidelines chapter provides specific guide- lines for programming with threads based upon the information presented in the previous chapters. These guidelines include best practices, performance and portability tips, and constructs to avoid.
Chapter 14: You have written your multithreaded application. It compiles. However, when running the application, you notice some unexpected behavior. Perhaps a value from a calculation is incorrect, I/O is interleaved, or perfor- mance is poor. Alternatively, you may notice that certain tasks are incomplete or maybe the entire program hangs. The Debugging Threaded Applications chapter presents symptoms, probable causes, and possible solutions for you to consider during your systematic debugging process.
4. Advanced Topics.
Chapter 15: The Parallel Programming Models and Issues chapter dis- cusses several software models suitable for multithreaded programs. Some mod- els are suitable for I/O-bound applications; others are suitable for compute- bound applications. The former exploit the concurrency benefit whereas the lat- ter uses parallelism to exploit the power of multiprocessor systems. A discussion of parallel programming issues follows. Several important issues relating to thread creation, thread synchronization, and multiprocessor cache thrashing are identified. Specific techniques, guidelines, and solutions are also presented.
5. Reference Material.
Appendix A: The Pthread Manual Pages in this appendix come directly from Hewlett-Packard's HP-UX Release 10.30. They appear in this book exactly as they appear on-line. Many thanks to Hewlett-Packard for allowing us to publish these manual pages.
Appendix B: Glossary.
Appendix C: Bibliography.
Conventions Used in this Book.
To assist in rapid learning and to provide ease of use, information in this book is presented in modular form. Chapters are divided into sections; each section cov- ers a particular topic. A section is composed of a title, descriptive picture, synoptic caption, full text explanation, and guidelines or code examples as appropriate. Here is a simplified example of a section:
Protecting Shared Objects.
Fig. 3-7 Use a mutex to serialize access to a shared object. If a piece of shared data will never be modified, a mutex is not needed.
A mutex is a mutual exclusion object that is used to serialize access to shared objects. Once a thread locks a mutex, other threads wishing to gain access to the shared object block until the mutex is unlocked.
Not all shared objects require protection. For example, if a piece of shared data will never be modified, there is no need to protect that data with a mutex.
* decide which shared objects require serial access
* use one mutex for each shared object requiring
The title of each section is given in the “Topics Covered” portion of each chap- ter introduction. Sections are presented in the same order listed. The last section in each chapter is followed by a chapter summary and exercises.
2. Use of Fonts.
Bold is used to indicate great importance.
Italics is used for definition of terms, emphasis, function arguments, or ref- erences to chapters (e.g., see Chapter 5, Thread Synchronization).
Courier is used for function names e.g., pthread_create() and for code examples.
Bold courier is used for macros and definitions referenced in the text.
CD-ROM and Code Examples
This book contains numerous code examples. To provide focus, many examples omit included files, declarations, and error checking. The CD-ROM packaged with Thread Time contains full, working versions of all code examples presented herein. In addition, templates are provided for several parallel programming models.
The CD-ROM has been formatted in the ISO 9660 and Rock Ridge file system formats. These formats are suitable for use on most operating system platforms. To access the code examples, mount the CD-ROM as a file system. The examples should then be copied to your local file system so that they may be compiled and/ or manipulated.
We're indebted to the following individuals who performed a full review of the technical material contained herein: Greg Astfalk, Bruce Blinn, Wayne A. Booth, Tom Doeppner, Edith Epstein, Duncan Missimer, Ann Schneider, Richard Mar- lon Stein, Tom Watson, and Joel Williamson. Their valuable feedback has gone a long way to improve the quality of this book. Special thanks to Ann Schneider for reviewing and editing the manuscript many times and answering countless edit- ing questions at all hours of the night. We would also like to thank Tony Coon, Marti Jones, Doug McKenzie, and Anil Rao for their constructive technical and editorial comments.
We would especially like to thank our families, Ann, Amy, and Ann, for their sup- port, patience, and encouragement throughout the writing of this book.
"About this title" may belong to another edition of this title.
Book Description Prentice Hall PTR, 1996. Paperback. Book Condition: New. book. Bookseller Inventory # 0131900676
Book Description Prentice Hall PTR, 1996. Book Condition: New. Brand New, Unread Copy in Perfect Condition. A+ Customer Service!. Bookseller Inventory # ABE_book_new_0131900676
Book Description Prentice Hall PTR, 1996. Paperback. Book Condition: New. Bookseller Inventory # P110131900676
Book Description Prentice Hall PTR, 1996. Paperback. Book Condition: New. UNOPENED CD - NEW - PERFECT - FAST SHIPPING & FREE TRACKING! 100% Money Back Guaranteed. The pages of this book are clean and unmarked. There is very little shelf wear. The spine is solid and the binding is tight. Bookseller Inventory # 132836
Book Description Prentice Hall PTR, 1996. Paperback. Book Condition: New. New item. Bookseller Inventory # QX-134-67-8820108
Book Description Prentice Hall PTR. PAPERBACK. Book Condition: New. 0131900676 New Condition. Bookseller Inventory # NEW6.0049303
Book Description Book Condition: Brand New. Book Condition: Brand New. Bookseller Inventory # 97801319006771.0