Jump to ratings and reviews
Rate this book

C++ Concurrency in Action: Practical Multithreading

Rate this book
Summary

C++ Concurrency in Action is a reference and guide to the new C++ 11 Standard for experienced C++ programmers as well as those who have never written multithreaded code. This book will show you how to write robust multithreaded applications in C++ while avoiding many common pitfalls.

About the TechnologyMultiple processors with multiple cores are the norm these days. The C++11 version of the C++ language offers beefed-up support for multithreaded applications, and requires that you master the principles, techniques, and new language features of concurrency to stay ahead of the curve.

About the BookWithout assuming you have a background in the subject, CC++ Concurrency in Action gradually enables you to write robust and elegant multithreaded applications in C++11. You'll explore the threading memory model, the new multithreading support library, and basic thread launching and synchronization facilities. Along the way, you'll learn how to navigate the trickier bits of programming for concurrency.

Written for C++ programmers who are new to concurrency and others who may have written multithreaded code using other languages, APIs, or platforms.

Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.

What's Inside
Written for the new C++11 Standard Programming for multiple cores and processors Small examples for learning, big examples for practice
====================

Table of Contents
Hello, world of concurrency in C++! Managing threads Sharing data between threads Synchronizing concurrent operations The C++ memory model and operations on atomic types Designing lock-based concurrent data structures Designing lock-free concurrent data structures Designing concurrent code Advanced thread management Testing and debugging multithreaded applications

528 pages, Paperback

First published January 1, 2009

126 people are currently reading
842 people want to read

About the author

Anthony Williams

4 books8 followers
Librarian note:
There is more than one author in the GoodReads database with this name

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
159 (47%)
4 stars
123 (37%)
3 stars
37 (11%)
2 stars
10 (3%)
1 star
3 (<1%)
Displaying 1 - 28 of 28 reviews
Profile Image for Nick Black.
Author 2 books879 followers
December 29, 2018
good stuff, the best coverage of C++11 concurrency i've seen in one place. i took away one star due to use of the term "benign data races", which Hans Boehm of HP pretty much proved not to exist in research papers of the 2012 era. kinda unfortunate that c++11 threading doesn't have cancellation in the Pthreads mold, but i can understand why, especially given the amount of fine-grained libc interaction necessary to support timely cancellation in the presence of system calls. very good coverage of atomics.
Profile Image for Alasdair Craig.
282 reviews14 followers
May 24, 2017
A very tough read on what is already a very advanced subject. It deserves reading twice, but I haven't got it in me to try again. A lot of code snippets which is good, but almost too much. An appendix on relevant C++11 constructs explains them better than anywhere else I've seen. I didn't get that aha moment when you see an entry point into a big subject. If it did anything for me it was to push me away from handling the nuts and bolts of multi-threading, and look more towards the concurrency abstractions like parallelism, OpenMP, PPL, AMP, etc.
25 reviews
March 31, 2019
The title of the book tells everything the reader needs to know about the contents of the book: it deals with concurrency from a C++ point of view and presents how the various facilities can be used in action. Thus, if anybody wants a book on concurrency, then the good news is that s/he probably found a good one, as no prior knowledge is required about this topic. The bad news is, that if somebody expects to simply pick up a book about concurrency while not concerning hemself/hirself about the language used to present the ideas (as it may be the case with many other books on various topics), then there will be some disappointment. But what does this all mean? Let's get into details:

First off, although no prior concurrency knowledge is required, a fair amount of C++ familiarity is, so one can't just pick this book up and expect great benefits without it. Not only that, but also a deep interest in C++ (and concurrcy) is highly recommended, as it gets (extremely) highly technical after a certain point, so it's also not necessarily for the casual reader. Just to reinforce this last statement, let me quote a praise from the book that kept popping into my mind as I was going through it: "Reading this made my brain hurt. But it's a good hurt." An it really is, but thanks to the author's well thought writing, the hurt doesn't really start until chapter 5, so the reader will get a comfortable amount of the proverbial calm before the storm. But after that, expect some serious stuff.

The calm part starts off really mildly in chapter 1 with an intro about concurrency, when and why it should (or shouldn't) be used, what is multithreading, how all these are supported in C++ and so on. Chapter 2 then continues with exploring threads and their management, which is followed by the explanation of the essential threading building blocks in the next two chapters. The author never misses to include a proper amount of code samples to present how and when these blocks are to be used. There will be plenty of talk about all the necessary theoretical background like deadlocks, various forms of race conditions, code structuring and so on, while guidelines like resource management, programming style, proper locking granularity, exception safety, etc. will not be excluded either.

One very interesting (and to me somewhat unexpected) inclusion in these early chapters was a short, yet very concise introduction to the chrono library, as a basic understanding of it is actually necessary for some of the threading facilities. It wasn't unexpected because it doesn't belong there (it actually does), but because unfortunately not all authors bother explaining stuff that is not strictly the topic of their books, so I was positively surprised. To me, little things like these really raise my appreciation level, as not needing to interrupt my reading experience (and focus) just to look up something that probably should've been included anyway, is a definite plus. Furthermore, the author wasn't scanty about providing an overlook about planned C++ threading facilities, as a significant part of chapter 4 delves precisely into this topic. One could ask why these not yet officially supported features are included in the first place, and I'd like to think because it gives the reader a rather clear vision where the language is headed in this regard.

Chapter 5 then quickly swirls into the promised storm. It starts the discussion with the C++ memory model and how it relates to concurrency and then dives deeper to present various forms of atomic operations and types. The really deep stuff comes at the end of the chapter, where memory ordering and various relationships are introduced. To be honest, I don't think a single read of this chapter (especially the last section of it) will suffice to make it sink in. Chapters 6 and 7 then deal with the creation of lock-based and lock-free concurrent data structures by providing plenty of guidelines, pitfalls and code examples. If one had doubts about the difficulties of writing proper concurrent code before, then all those doubts will be dispelled in these chapters for sure. Despite their difficult nature however, they are still very useful even to those, who do not wish to write concurrent containers, as proper usage of the basic building blocks introduced in the first half of the book is clearly shown here in action. Speaking about action, the book also includes an entire chapter where all these building blocks are used to increase performance of some common algorithms (with all associated pitfalls, guidlines, etc.), so the author truly delivers on the 'in action' part of the title.

If it wasn't enough already, advanced threading paradigms like thread pools and thread interruption will also be presented along with overall design guidelines for writing concurrent code. There will also be a small section on debugging and testing, mostly for the sake of completeness and probably to give the reader a softer outro after all the complicated stuff. Finally, the book also contains a rather large appendix section (about 1/3 of the total pages) which can serve as a reference to the modern features and concurrency part of C++.

So is there a problem with this book one might ask? I don't think there is (significant ones anyway), as it excels at the thing it set out for. There are plenty of code examples, discussions, explanations, introductions and the choice and order of topics are excellent. And here I'd like to dwell a bit on the order, as some books in the programming field like to forward reference themselves (use concepts that will only be explained later in the book), but not this one. Everything is laid down properly in time as it should be. If I were pressed hard to find a problem though, then the only thing (not a great deal really) I would say is the somewhat legacy nature of the presented code. Don't get me wrong, it is not ancient style, but there are cases where it could be upgraded for better readability, like trying to replace the bit obscure 'typedef typename std::result_of::type result_type' with an easier to understand 'using result_type = std::result_of_t'; or maybe using 'auto' instead of 'std::shared_ptr' where 'std::make_shared' is used on the right side of the statement anyway. As I have said, these are not significant problems and since the author expects good knowledge of C++, these will not be a showstopper.

All in all, this is an excellent and challenging book intended for those who are interested in and appreciate both C++ and concurrency. If you are new to concurrency, then this is definitely worth your time, but be warned: if you don't have proper understanding of the language itself, you will then be struggling with it far more than necessary. I'd even go as far as saying that this book has prerequisite literature, like Stroustrup's A Tour of C++, Second Edition and Meyers' Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C++14 to actually have a chance of really learning from it. Finally, because of the challenging nature of this piece, don't expect a single read to be enough, so prepare for putting in extra effort to your usual learning methods, like creating diagrams and mental images of the execution sequences to fully benefit from it.
Profile Image for Joe.
108 reviews1 follower
March 9, 2020
Great reference, but a tough read from cover to cover.

What I liked about the book:
- great examples, both of good and bad design patterns for concurrency in c++
- different approaches to concurrency (mutexes and atomics) discussed with appropriate grounding in performance
- high- (locks and mutexes) and low-level approaches (memory model and atomics) discussed each in detail
- appendices contain complete reference for the concurrency parts of the c++11 standard, as well as other language features.
- the book concluded with the practical consideration of how to test concurrent code

I'm sure I will refer to this book a lot in my daily work.
Profile Image for Moritz.
46 reviews2 followers
April 11, 2021
I liked it. A good introduction to multithreading in C++. At times it is a little bit wordy. I think it could be a little bit shorter, but I don't like skipping parts. It is not as good as some other C++ books out there (Scott Meyers), but maybe that is a too high of a bar. Maybe it is me, but I found the code listings quite ugly. Probably it is a combination of me not being used to the authors coding style and the formatting of the code on the printed page.

TLDR: Read the book if you want to learn more about multithreading in C++. It is not as amazing as some other C++ books out there, but it does the job.
Profile Image for lehaleha.
60 reviews2 followers
February 11, 2016
Covers in detail most common areas of multithreaded programing using C++11 features. Not super-advanced reading, but good intermediate one for sure.
Profile Image for Qiongsi Wu.
5 reviews1 follower
August 27, 2019
A very good book on this material. It even teaches concurrent programming better than my operating system's class.

The good. The organization of the book is neat. Code examples are very clearly annotated and easy to follow. The use of modern C++ is nice - it helps me learn both multi-threaded programming and modern C++ together.

On the other hand, maybe I missed them when reading it, there is a lack of examples with performance numbers. Maybe it is not necessary, but I am interested in doing the coding myself and measure them against what is in the book.
Profile Image for Fredrik Ismyren.
11 reviews
August 18, 2024
Williams, en expert på parallell multiprocessorprogrammering med examina från universitetet i Oxford och skapare av concurrencybiblioteket Just::Thread Pro, täcker in det mesta på området som inte är patenterat. Tydliga beskrivande exempel från en person med god utlärningsförmåga. Det här är en av de bästa böckerna på området.
52 reviews
April 4, 2017
An excellent and comprehensive introductory to intermediate book on the practice of writing parallel to C++.
Profile Image for Sofie Giocante.
14 reviews17 followers
September 4, 2019
The very best book about this topic. I LEARNED lot from this book — thanks to authors.
4 reviews
September 7, 2021
Quite an amazing book on the subject of concurrency through multithreading in C++. Nothing comes close to it when it comes to C++ multithreading support.
Profile Image for Hà Bùi.
36 reviews14 followers
March 3, 2022
Through explanation about multithreading C++.
I would love if the book has more hands-on examples.
Profile Image for Simón.
158 reviews
March 2, 2017
A very detailed walkthrough of C++ concurrency, this book requires actually working with the APIs and techniques it describes, as otherwise it becomes too hard to stay focused.

The lock-free design chapter is priceless, and the C++11 appendix is almost as good as a dedicated C++11 book. Finally, the concurrency API reference also included as an appendix can be very useful.

More a reference book to have near your desk than a technical book to read while commuting, C++ Concurrency is a worthy investment.
Profile Image for Dan Dexter.
5 reviews
August 27, 2014
C++ Concurrency In Action is definitely on my list of top five software engineering books. Anthony Williams writing style is very refreshing and he presents the material in a way that keeps the material both interesting and engaging. The book is written such that someone new to the topic of concurrent programming can get a good introduction while also being able to cater to the more advanced crowd with topics such as the C++ Memory Model (in regards to concurrency and memory ordering), lock-free data structures, and common design patterns. While this book advertises its main focus being on concurrency, it's also exceptional at educating the reader on additions made to the C++11 standard, both in relation to concurrency and not. I highly recommend this book.
1 review3 followers
September 6, 2016
The book is a great resource for learning concurrent programming, I definitely learned a lot. It's also a good resource for how to solve specific real life engineering problems.

It teaches the mechanics and goes through many common patterns of how to do things safely and efficiently. It also explains well why things work - theory parts are good.

My favorite part was designing concurrent data structures. It gave me some good insights.
Profile Image for Eugene.
15 reviews1 follower
April 7, 2015
Great for newbies. Good details about memory ordering, lock-free data structures and fine-grained locks.
Useless reference of C++11 standard concurrency classes and functions.
No real numbers or underlying asm instructions, even for x86 architecture.
Profile Image for Alexandar Mechev.
28 reviews10 followers
November 14, 2015
Although at times the author skips a logical step in his explanation, which means the reader has to parse some paragraphs multiple times, overall the book is a great introduction to concurrent programming.
Profile Image for Alastair.
17 reviews8 followers
February 29, 2012
Good intro to the new C++11 concurrency library, from a very credible author. Would have liked to see more demonstrated results (e.g. exactly how much faster? how much more scalability?)
Profile Image for Tudor Ștefănescu.
49 reviews2 followers
October 27, 2013
really good introduction of the new C++11 features - both for multithreading and for general use. A book to read and re-visit.
41 reviews
June 6, 2016
Clear explanation of various tools for developing concurrent systems in C++11, potential problems and ways to find and solve them. It's one of those books which requires several readings
Profile Image for Dayton Outar.
113 reviews5 followers
October 1, 2024
This was a good refresher and practical for concurrency, threads and processes in operating systems.
30 reviews
April 7, 2017
Сравнивая стиль написания данной книги с книгами Скотта Майерса, конечно, видны определенные недостатки из-за которых книга читается не так легко.
Начинается все с азов, постепенно усложняясь, так что данная книга подходит всем, и желающим проверить свои знания в многопоточности, и желающим добавить расширить их.
Displaying 1 - 28 of 28 reviews

Can't find what you're looking for?

Get help and learn more about the design.