| |
1. Covering Multithreading Basics | 1 |
| ..Defining Multithreading Terms | 2 |
| ....Defining Concurrency and Parallelism | 2 |
| ..Benefiting From Multithreading | 3 |
| ....Improve Application Responsiveness | 3 |
| ....Use Multiprocessors Efficiently | 3 |
| ....Improve Program Structure | 3 |
| ....Use Fewer System Resources | 3 |
| ....Combine Threads and RPC | 4 |
| ....Improve Performance | 4 |
| ..Looking At Multithreading Structure | 5 |
| ....User-level Threads | 6 |
| ....Lightweight Processes | 8 |
| ....Unbound Threads | 9 |
| ....Bound Threads | 9 |
| |
| ..Meeting Multithreading Standards | 10 |
2. Programming With Threads | 11 |
| ..The Threads Library | 11 |
| ....Create a Thread--the Basics | 12 |
| ....Get the Thread Identifier | 14 |
| ....Yield Thread Execution | 14 |
| ....Suspend or Continue Thread Execution | 15 |
| ....Send a Signal to a Thread | 16 |
| ....Access the Signal Mask of the Calling Thread | 16 |
| ....Terminate a Thread | 17 |
| ....Wait for Thread Termination | 19 |
| ....A Simple Threads Example | 21 |
| ....Maintain Thread-Specific Data | 22 |
| ....Create a Thread--Advanced Features | 27 |
| ....Get the Minimal Stack Size | 32 |
| ....Get and Set Thread Concurrency Level | 33 |
| ....Get and Set Thread Priority | 34 |
| ....Scheduling and the Threads Library | 35 |
3. Programming With Synchronization Objects | 37 |
| ..Mutual Exclusion Locks | 38 |
| ....Initialize a Mutual Exclusion Lock | 39 |
| ....Lock a Mutex | 40 |
| ....Lock With a Nonblocking Mutex | 40 |
| ....Unlock a Mutex | 41 |
| |
| ....Destroy Mutex State | 42 |
| ....Mutex Lock Code Example | 43 |
| ....Nested Locking With a Singly Linked List | 46 |
| ....Nested Locking With a Circular Linked List | 47 |
| ..Condition Variables | 48 |
| ....Initialize a Condition Variable | 49 |
| ....Block on a Condition Variable | 50 |
| ....Unblock a Specific Thread | 51 |
| ....Block Until a Specified Event | 52 |
| ....Unblock All Threads | 54 |
| ....Destroy Condition Variable State | 55 |
| ....The Lost Wake-Up Problem | 56 |
| ....The Producer/Consumer Problem | 56 |
| ..Multiple-Readers, Single-Writer Locks | 60 |
| ....Initialize a Readers/Writer Lock | 61 |
| ....Acquire a Read Lock | 62 |
| ....Try to Acquire a Read Lock | 62 |
| ....Acquire a Write Lock | 63 |
| ....Try to Acquire a Write Lock | 64 |
| ....Unlock a Readers/Writer Lock | 64 |
| ....Destroy Readers/Writer Lock State | 65 |
| .. Semaphores | 66 |
| ....Counting Semaphores | 68 |
| ....Initialize a Semaphore | 69 |
| |
| ....Increment a Semaphore | 70 |
| ....Block on a Semaphore Count | 70 |
| ....Decrement a Semaphore Count | 71 |
| ....Destroy the Semaphore State | 72 |
| ....The Producer/Consumer Problem, Using Semaphores | 73 |
| ..Synchronization Across Process Boundaries | 75 |
| ..Comparing Primitives | 77 |
4. Programming With the Operating System | 79 |
| ..Processes--Changes for Multithreading | 79 |
| ....Duplicating Parent Threads | 79 |
| ....Executing Files and Terminating Processes | 81 |
| ..Alarms, Interval Timers, and Profiling | 81 |
| ..Nonlocal Goto--setjmp(3C) and longjmp(3C) | 82 |
| ..Resource Limits | 82 |
| ..LWPs and Scheduling Classes | 82 |
| ....Timeshare Scheduling | 83 |
| ....Realtime Scheduling | 84 |
| ....LWP Scheduling and Thread Binding | 84 |
| ....SIGWAITING--Creating LWPs for Waiting Threads | 85 |
| ....Aging LWPs | 85 |
| ..Extending Traditional Signals | 86 |
| ....Synchronous Signals | 87 |
| ....Asynchronous Signals | 87 |
| ....Continuation Semantics | 88 |
| |
| ....New Operations on Signals | 89 |
| ....Thread-Directed Signals | 90 |
| ....Completion Semantics | 92 |
| ....Signal Handlers and Async Safety | 93 |
| ....Interrupted Waits on Condition Variables | 94 |
| ..I/O Issues | 96 |
| ....I/O as a Remote Procedure Call | 96 |
| ....Tamed Asynchrony | 96 |
| ....Asynchronous I/O | 97 |
| ....Shared I/O and New I/O System Calls | 98 |
| ....Alternatives to getc(3S) and putc(3S) | 99 |
5. Safe and Unsafe Interfaces | 101 |
| ..Thread Safety | 101 |
| ..MT Interface Safety Levels | 103 |
| ....Reentrant Functions for Unsafe Interfaces | 104 |
| ..Async-Safe Functions | 105 |
| ..MT Safety Levels for Libraries | 105 |
| ....Unsafe Libraries | 106 |
6. Compiling And Debugging | 107 |
| ..Compiling a Multithreaded Application | 107 |
| ....Using The C Compiler | 107 |
| ....Compiling With the _REENTRANT Flag | 108 |
| ....Using libthread | 108 |
| ....Using Non-C Compilers | 109 |
| |
| ..Debugging Multithreaded Programs | 109 |
| .....Common Oversights | 109 |
| .....Using adb | 110 |
| .....Using dbx | 111 |
7. Programming Guidelines | 113 |
| ..Rethinking Global Variables | 114 |
| ..Providing For Static Local Variables | 115 |
| ..Synchronizing Threads | 115 |
| .....Single-Threaded Strategy | 116 |
| .....Reentrance | 116 |
| ..Avoiding Deadlock | 119 |
| .....Scheduling Deadlocks | 120 |
| .....Locking Guidelines | 120 |
| ..Following Some Basic Guidelines | 121 |
| .....Creating Threads | 122 |
| ..Working With Multiprocessors | 124 |
| .....The Underlying Architecture | 124 |
| .....Summary | 130 |
A. Sample Application Code | 131 |
| ..File Copy | 131 |
| ..Matrix Multiplication | 133 |
| ..RPC Program | 135 |
| ..Window System Server | 141 |
B. MT Safety Levels: Library Interfaces | 145 |