1. Trang chủ
  2. » Công Nghệ Thông Tin

c++ concurrency in action

530 1K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 530
Dung lượng 6,58 MB

Nội dung

MANNING Anthony Williams Practical Multithreading IN ACTION www.it-ebooks.info C++ Concurrency in Action www.it-ebooks.info www.it-ebooks.info C++ Concurrency in Action P RACTICAL M ULTITHREADING ANTHONY WILLIAMS MANNING S HELTER I SLAND www.it-ebooks.info For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2012 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Cynthia Kane 20 Baldwin Road Technical proofreader: Jonathan Wakely PO Box 261 Copyeditor: Linda Recktenwald Shelter Island, NY 11964 Proofreader: Katie Tennant Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781933988771 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 18 17 16 15 14 13 12 www.it-ebooks.info To Kim, Hugh, and Erin www.it-ebooks.info www.it-ebooks.info vii brief contents 1 ■ Hello, world of concurrency in C++! 1 2 ■ Managing threads 15 3 ■ Sharing data between threads 33 4 ■ Synchronizing concurrent operations 67 5 ■ The C++ memory model and operations on atomic types 103 6 ■ Designing lock-based concurrent data structures 148 7 ■ Designing lock-free concurrent data structures 180 8 ■ Designing concurrent code 224 9 ■ Advanced thread management 273 10 ■ Testing and debugging multithreaded applications 300 www.it-ebooks.info www.it-ebooks.info ix contents preface xv acknowledgments xvii about this book xix about the cover illustration xxii 1 Hello, world of concurrency in C++! 1 1.1 What is concurrency? 2 Concurrency in computer systems 2 Approaches to concurrency 4 1.2 Why use concurrency? 6 Using concurrency for separation of concerns 6 Using concurrency for performance 7 ■ When not to use concurrency 8 1.3 Concurrency and multithreading in C++ 9 History of multithreading in C++ 10 ■ Concurrency support in the new standard 10 ■ Efficiency in the C++ Thread Library 11 ■ Platform-specific facilities 12 1.4 Getting started 13 Hello, Concurrent World 13 1.5 Summary 14 www.it-ebooks.info [...]... in a single process tion between threads The low overhead associated with launching and communicating between multiple threads within a process compared to launching and communicating between multiple single-threaded processes means that this is the favored approach to concurrency in mainstream languages including C++, despite the potential problems arising from the shared memory In addition, the C++. .. want to use concurrency and multithreading in your applications ■ Some of the history of the support for concurrency in C++ ■ What a simple multithreaded C++ program looks like These are exciting times for C++ users Thirteen years after the original C++ Standard was published in 1998, the C++ Standards Committee is giving the language and its supporting library a major overhaul The new C++ Standard... with sharing data between threads 34 Race conditions 3.2 35 ■ Avoiding problematic race conditions Protecting shared data with mutexes 36 37 Using mutexes in C++ 38 Structuring code for protecting shared data 39 Spotting race conditions inherent in interfaces 40 Deadlock: the problem and a solution 47 Further guidelines for avoiding deadlock 49 Flexible locking with std::unique_lock 54 Transferring mutex... variable wait 291 Interrupting a wait on std::condition_variable_any 294 Interrupting other blocking calls 296 Handling interruptions 297 Interrupting background tasks on application exit 298 ■ ■ ■ ■ ■ 9.3 10 Summary 299 Testing and debugging multithreaded applications 300 10.1 Types of concurrency- related bugs Unwanted blocking 301 10.2 ■ 301 Race conditions 302 Techniques for locating concurrency- related... multithreaded programming in particular, to improve application performance This book is about writing programs in C++ using multiple threads for concurrency and the C++ language features and library facilities that make that possible I’ll start by explaining what I mean by concurrency and multithreading and why you would want to use concurrency in your applications After a quick detour into why you might... achieved through task switching or by genuine hardware concurrency But as you may imagine, how you make use of concurrency in your application may well depend on the amount of hardware concurrency available This is covered in chapter 8, where I cover the issues involved with designing concurrent code in C++ 1.1.2 Approaches to concurrency Imagine for a moment a pair of programmers working together on a software... original developer, I jumped at the chance to get involved I have been the primary developer and maintainer of the Boost Thread Library ever since xv www.it-ebooks.info xvi PREFACE As the work of the C++ Standards Committee shifted from fixing defects in the existing standard to writing proposals for the next standard (named C++0 x in the hope that it would be finished by 2009, and now officially C++1 1,... manufacturers have increasingly been favoring multicore designs with 2, 4, 16, or more processors on a single chip over better performance with a single core Consequently, multicore desktop computers, and even multicore embedded devices, are now increasingly prevalent The increased computing power of these machines comes not from running a single task faster but from running multiple tasks in parallel In the past,... use concurrency in your application, whether for performance, separation of concerns, or because it’s “multithreading Monday,” what does that mean for C++ programmers? 1.3 Concurrency and multithreading in C++ Standardized support for concurrency through multithreading is a new thing for C++ It’s only with the upcoming C++1 1 Standard that you’ll be able to write multithreaded code without resorting... a dual-core machine (which has two processing cores), each task can execute on its own core On a single-core machine doing task switching, the chunks from each task are interleaved But they are also spaced out a bit (in the diagram this is shown by the gray bars separating the chunks being thicker than the separator bars shown for the dual-core machine); in order to do the interleaving, the system . MANNING Anthony Williams Practical Multithreading IN ACTION www.it-ebooks.info C++ Concurrency in Action www.it-ebooks.info www.it-ebooks.info C++ Concurrency in Action P RACTICAL M ULTITHREADING ANTHONY. of concurrency in C++! 1 1.1 What is concurrency? 2 Concurrency in computer systems 2 Approaches to concurrency 4 1.2 Why use concurrency? 6 Using concurrency for separation of concerns 6 Using. concerns 6 Using concurrency for performance 7 ■ When not to use concurrency 8 1.3 Concurrency and multithreading in C++ 9 History of multithreading in C++ 10 ■ Concurrency support in the new standard

Ngày đăng: 03/04/2015, 15:23

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN