C++ConcurrencyinActionPracticalMultithreading
最好的C++ 11 多线程课程CopyrightForonlineinformationandorderingofthisandotherManningbookspleasevisitwww.manning.com.The publisher offers discounts on this book when ordered in quantity. For more information, pleasecontactSpecial Sales DepartmentManning publications Co2⊙ Baldwin roadPO BOx 261Shelter Island, NY 11964Email:orders@manning.comC2012 by Manning Publications Co. All rights reservedNo part of this publication may be reproduced, stored in a retrieval system, or transmitted, in anyform or by means electronic, mechanical, photocopying, or otherwise, without prior writtenpermission of the publisherMany of the designations used by manufacturers and sellers to distinguish their products are claimedas trademarks. Where those designations appear in the book, and manning publications was aware ofa trademark claim, the designations have been printed in initial caps or all capsRecognizing the importance of preserving what has been written, it is Mannings policy to have the books wepublish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibilityto conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycledand processed without the use of elemental chlorineDevelopment editor: Cynthia KaManning Publications CoTechnical proofreader: Jonathan Wakely20 Baldwin roadCopyeditor: Linda RecktenwaldPO BOx 261Proofreader: Katie TennantShelter island ny 11964Typesetter: Dennis dalinnikCover designer: Marija TudorPrinted in the United States of america12345678910MAL-18171615141312Dedicationo Kim hugh and erinBrief table of contentsCopyrightBrief Table of contentsTable of contentsPrefaceAcknowledgmentsabout This bookabout the cover illustrationChapter 1. Hello, world of concurrency in C++Chapter 2. Managing threadsChapter 3. Sharing data between threadsChapter 4. Synchronizing concurrent operationsChapter 5. The C++ memory model and operations on atomic typesChapter 6. Designing lock-based concurrent data structuresChapter 1. Designing lock-free concurrent data structuresChapter 8. designing concurrent codeChapter 9. Advanced thread managementChapter 10. Testing and debugging mul ti threaded applicationsAppendix A Brief reference for some C++ll language featuresAppendix B. Brief comparison of concurrency librariesAppendix C. a message-passing framework and complete ATM exampleAppendix D. C++ Thread Library referenceResourcesIndexist of figuresList of tablesList of listingsTable of contentsCopyrightBrief Table of contentsTable of contentsPrefaceAcknowledgmentsabout This bookabout the cover illustrationChapter 1. Hello, world of concurrency in C++1. 1. What is concurrency?LLL Concurrency in computer systems1. 2. approaches to concurrency1. 2. Why use concurrency?1.2.1. USing concurrency for separation of concerns1.2.2.USing concurrency for performance1.2.3. When not to use concurrency1.3. Concurrency and mul tithreading in C++3. 1. History of mul ti threading in C++1.3.2. Concurrency support in the new standard1.3.3. Efficiency in the C++ Thread Library1.3. 4. Platform-specific facilities1. 4. Getting started1. 4.1.Hello, Concurrent World15.SuAmmarChapter 2. Managing threads2. 1. Basic thread management1. 1. Launching a thread1. 2. Waiting for a thread to complete2. 1.3. Waiting in exceptional circumstances2. 1. 4. Running threads in the background2. 2. Passing arguments to a thread function2.3. Transferring ownership of a thread2.4. Choosing the number of threads at runtime2.5.Identifying threads2.6. SummaryChapter 3. Sharing data between threads3. 1. Problems with sharing data between threads3.1.1. Race conditions3. 1.2, Avoiding problematic race conditions32. Protecting shared data with mutexes2. 1. Using mutexes in C++3.2.2. Structuring code for protecting shared data3.2.3. Spotting race conditions inherent in interfaces2. 4. Deadlock: the problem and a solution3.2.5. Further guidelines for avoiding deadlock3.2.6.Flexible locking with std: unique_lock3.2.7. Transferring mutex ownership between scopes3. 2.8. Locking at an appropriate granularity3.3. Alternative facilities for protecting shared data3.3.1. Protecting shared data during initialization3.3.2. Protecting rarely updated data structures3.3.3. Recursive locking3. 4. SummaryChapter 4. Synchronizing concurrent operations4.1 Waiting for an event or other condition4.1.1. Waiting for a condition with condition variables4.1.2. Building a thread-safe queue with condition variables42. Waiting for one-off events with futures2. 1. Returning values from background tasks4.2.2. Associating a task with a futurepromises4.2.4. Saving an exception for the future2.5. Waiting from multiple threads43. Waiting with a time limit4.3.1. Clocks43.2. Durations4.3.3. Time points4.3. 4. Functions that accept timeouts4. 4. USing synchronization of operations to simplify code4.4.1. Functional programming with futures4.4.2. Synchronizing operations with message passing4.5. SummaryChapter 5. The C++ memory model and operations on atomic types5. 1. Memory model basics5.1. 1 Obiects and memory locations5.1.2. Objects, memory locations, and concurrency5.1.3. Modification orders5. 2. Atomic operations and types in C++2. 1. The standard atomic types5. 2.2. Operations on std: atomic flag5.2. 3. Operations on std: atomic5. 4. Operations on std: atomic: pointer arithmetic2.5.Operations on standard atomic integral types5.2.6. The std: atomice primary class template5.2. 7. Free functions for atomic operations5.3. Synchronizing operations and enforcing ordering5.3. 1. The synchronizes-with relationship5.3. 2. The happens-before relationship3.3. Memory ordering for atomic operations5.3.4. Release sequences and synchronizes-with5.3 4. Fences5.3.6. Ordering nonatomic operations with atomics5. 4. SummaryChapter 6. Designing lock-based concurrent data structures6. 1. What does it mean to design for concurrency?1.1. Guidelines for designing data structures for concurrency6.2. Lock-based concurrent data structures6.2. 1. A thread-safe stack using locks6.2.2. A thread-safe queue using locks and condition variables6.2.3. A thread-safe queue using fine-grained locks and condition variables6.3. Designing more complex lock-based data structures6.3.1. Writing a thread-safe lookup table using locks6.3. 2. Writing a thread-safe list using locksummaryChapter 7. Designing lock-free concurrent data structures7.1. Definitions and consequences7.1.1. Types of nonblocking data structures1. 2. Lock-free data structures713. Wait-free data structures7. 4. The pros and cons of lock-free data structures7.2. Examples of lock-free data structures7.2.1. Writing a thread-safe stack without locks7.2.2. Stopping those pesky leaks: managing memory in lock-free data structures7.2.3. Detecting nodes that cant be reclaimed using hazard pointers7. 2. 4. Detecting nodes in use with reference counting1.2.5. Applying the memory model to the lock-free stack1.2.6. Writing a thread-safe queue without locks73. Guidelines for writing lock-free data structures7.3.1. Guideline: use std: memory order seq cst for prototyping7.3.2. Guideline: use a lock-free memory reclamation scheme1.3.3. Guideline: watch out for the ABaproblem7.3.4. Guideline: identify busy-wait loops and help the other thread7.4. SummaryChapter 8. Designing concurrent code8. 1. Techniques for dividing work between threads8.1.1.Dividing data between threads before processing begins8. 1.2. Dividing data recursively8. 1.3. Dividing work by task type8. 2. Factors affecting the performance of concurrent code8.2. 1 How many processors8.2. 2 Data contention and cache ping-pong8.2.3. False sharing8.2. 4. How close is your data?8.2.5. Oversubscription and excessive task switching8.3. Designing data structures for multithreaded performance8.3.1. Dividing array elements for complex operations8.3.2. Data access patterns in other data structures8.4. Additional considerations when designing for concurrency8. 1. Exception safety in parallel algorithms8.4.2. Scalability and Amdahl's la8.4.3. Hiding latency with multiple threads8.4.4. Improving responsi veness with concurrency8.5. Designing concurrent code in practice8.5.1. A parallel implementation of std: for each8.5.2. A parallel implementation of std: find8.5.3. A parallel implementation of std: partial sum
用户评论