{"id":1496,"date":"2019-03-10T06:03:47","date_gmt":"2019-03-10T00:33:47","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=1496"},"modified":"2019-03-10T10:16:23","modified_gmt":"2019-03-10T04:46:23","slug":"book-review-c-concurrency-in-action","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2019\/03\/10\/book-review-c-concurrency-in-action\/","title":{"rendered":"Book Review: C++ Concurrency in Action"},"content":{"rendered":"<h3><em><strong>Title: C++ Concurrency in Action<\/strong><\/em><\/h3>\n<h3><em><strong>Author: Anthony Williams<\/strong><\/em><\/h3>\n<h3><em><strong>Publisher: Manning Publications Co.<\/strong><\/em><\/h3>\n<h3><em><strong>Year: 2019 (Second Edition)<\/strong><\/em><\/h3>\n<p>&nbsp;<\/p>\n<p>The first edition of this book came out in the year 2012 and covered the concurrency features of <em><strong>C++ 11<\/strong><\/em>. Much has happened since then. The present <em><strong>C++17<\/strong><\/em> is significantly richer in terms of concurrency support, especially in the area of parallel algorithms. The release of the second edition of the book recently is a nice addition to the growing number of good books on <em><strong>C++ 17<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>The book contains <strong>11<\/strong> chapters. The major difference between this edition and the earlier one is that <strong>Chapter 10<\/strong> on <em><strong>\u201cParallel Algorithms\u201d<\/strong><\/em> is completely new in this second edition.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>The first two chapters touch upon the basics of threading, including creating threads, waiting for threads to complete, and transferring ownership of threads. There is also a brief discussion on how to determine the number of threads supported by the hardware so that one can dynamically decide the optimal number of threads to spawn.<\/p>\n<p><strong>Chapter 3<\/strong> talks about the problems of sharing data across multiple threads and the typical use of <em><strong>mutexes<\/strong><\/em> to do this correctly. Some interesting, but less common, cases can be handled through the use of <em><strong>std::call_once()<\/strong><\/em> function. This is also described in this section.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Synchronizing concurrent operations is the focus of the fourth chapter. <em><strong>Condition variables<\/strong><\/em>, <em><strong>Futures<\/strong><\/em> and <em><strong>Promises<\/strong><\/em> are covered here. One of the interesting sections in this chapter is about the continuation-style concurrency as specified in the <strong>Concurrency TS<\/strong>. This functionality, although not yet in the standard, is available through the <em><strong>std::experimental<\/strong><\/em> namespace.<\/p>\n<p><strong>Chapter 5<\/strong> covers the important topic of <strong>C++<\/strong> <em><strong>memory model<\/strong> <\/em>from the perspective of threading. I would even go to the extent of saying that this should have been the first chapter of the book, because everything else depends on this foundation.<\/p>\n<p><strong>Chapters 6<\/strong> and <strong>7<\/strong> discuss how one can design <em><strong>concurrent data structures<\/strong><\/em> that are both thread-safe and allow genuine concurrency. Although the general advice is to use standard data structures and algorithms from the library, often times, we have to implement our own data structures that are domain specific. These two chapters explain how to achieve this.<\/p>\n<p>In <strong>Chapter 8<\/strong>, the author gives broad guidelines on how to design <em><strong>concurrent code<\/strong><\/em>. Important concerns about performance, scalability and exception safety are discussed here. These are practical issues that a developer needs to be aware of.<\/p>\n<p><strong>Chapter 9<\/strong> touches upon the finer aspects of thread management. The two key concepts covered in this chapter are <em><strong>thread pooling<\/strong><\/em> and <em><strong>thread interruption<\/strong><\/em>. Both are important and are widely used in real-world applications.<\/p>\n<p><strong>Chapter 10<\/strong> is about the support for parallel algorithms in <em><strong>STL<\/strong><\/em>. This functionality is one of the major additions in <em><strong>C++17<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0 <\/span>Several STL algorithms, including copy, find, sort, and transform can now execute in parallel. This chapter gives examples using the different execution policies <em><strong>std::execution::seq<\/strong><\/em>, <em><strong>std::execution::par<\/strong><\/em>, <em><strong>std::execution::par_unseq<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p><em><strong>Testing and debugging<\/strong><\/em> multithreaded code is quite a challenge. <strong>Chapter 11<\/strong> covers this topic and has some useful tips.<\/p>\n<p>There are 4 appendices at the end of the book. <strong>Appendix A<\/strong> is titled <em><strong>\u201cBrief reference for some C++11 language features\u201d<\/strong><\/em>. This seems a bit odd in a book that discusses concurrency as supported in <em><strong>C++17<\/strong><\/em>. The author could have added some features of <em><strong>C++14<\/strong><\/em> and <em><strong>C++17<\/strong><\/em> to this chapter (there is just one additional topic <em><strong>\u201cClass Template Argument Deduction\u201d<\/strong><\/em> compared to the previous edition).<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p><strong>Appendix B<\/strong> provides a single-page comparison of the concurrency features of <em><strong>\u201cJava\u201d<\/strong><\/em>, <em><strong>\u201cPosix C\u201d<\/strong><\/em>, <em><strong>\u201cBoost Threads\u201d<\/strong><\/em>, and <em><strong>\u201cC++11\u201d<\/strong><\/em>. This part has been retained as it is from the First edition. I would have liked it if it had been updated to the current standard, and some additional languages included (for example, concurrency in <em><strong>C#<\/strong><\/em>, <em><strong>go<\/strong><\/em>, etc.).<\/p>\n<p><strong>Appendix C<\/strong> contains the complete source code for the <em><strong>message-passing framework<\/strong><\/em> and <em><strong>ATM<\/strong><\/em> example discussed earlier in the book. I am surprised that even this code is identical to the earlier version. The author could have used this larger example to showcase some of the newer concurrency features covered in the book.<\/p>\n<p>The last appendix, spanning 150 pages, is a reference to the <em><strong>C++<\/strong> <strong>thread library<\/strong><\/em>. Although it can be handy when you are reading the book, I personally prefer the online reference, for example, <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/thread\/thread\/thread\" target=\"_blank\" rel=\"noopener\"><em><strong>this<\/strong><\/em><\/a>.<\/p>\n<p>Overall, this is a very useful and readable book, one that every <em><strong>C++<\/strong><\/em> developer must have. However, having read the first edition, I feel the author could have added some more useful material in this revised edition; it feels like he was in a hurry to release the book because it was already overdue. Of course, if you do not have the first edition, now is the best time to get this revised edition.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Title: C++ Concurrency in Action Author: Anthony Williams Publisher: Manning Publications Co. Year: 2019 (Second Edition) &nbsp; The first edition of this book came out in the year 2012 and covered the concurrency features of C++ 11. Much has happened since then. The present C++17 is significantly richer in terms of concurrency support, especially in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[94,49,17],"tags":[195,196,197],"class_list":["post-1496","post","type-post","status-publish","format-standard","hentry","category-book-review","category-c","category-programming","tag-c-17","tag-concurrency","tag-multi-threading"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-o8","jetpack-related-posts":[{"id":2868,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/07\/11\/book-review-beautiful-c-30-core-guidelines-for-writing-clean-safe-and-fast-code\/","url_meta":{"origin":1496,"position":0},"title":"Book Review &#8211;  Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code","author":"admin","date":"July 11, 2022","format":false,"excerpt":"Title: Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code Authors: J.Guy Davidson, Kate Gregory Publisher:\u00a0 Pearson Education Year: 2022 My earliest introduction to C++ guidelines was through Scott Meyers\u2019 excellent book Effective C++ that first appeared in 1992. After programming in C++ for around 3 years\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/Book-Cover2-233x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":988,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/07\/22\/book-review-design-patterns-in-modern-c\/","url_meta":{"origin":1496,"position":1},"title":"Book Review &#8211; Design Patterns in Modern C++","author":"admin","date":"July 22, 2018","format":false,"excerpt":"Title: Design Patterns in Modern C++ - Reusable Approaches for Object-Oriented Software Design Author: Dmitri Nesteruk Publisher: Apress Year: 2018 Luck has been on my side for the past few weeks; I have been getting access to nice books to read. I wrote about The\u00a0Modern C++ Challenge in my last\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":190,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/03\/15\/book-review-common-lisp-recipes-by-edi-weitz\/","url_meta":{"origin":1496,"position":2},"title":"Book Review: Common Lisp Recipes &#8211; A Problem-Solution Approach","author":"admin","date":"March 15, 2016","format":false,"excerpt":"Last Saturday (March 12, 2016), I got my most eagerly awaited book from Amazon.com. Yes, I am talking about Common Lisp Recipes: A Problem-Solution Approach\u00a0authored by Dr.Edmund Weitz. Of course, if you have been programming in Lisp for a couple of years, you would have definitely heard of Dr.Edi Weitz,\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2935,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/11\/07\/why-learn-c\/","url_meta":{"origin":1496,"position":3},"title":"Why Learn C++","author":"admin","date":"November 7, 2022","format":false,"excerpt":"This is the third and the last article in the series \u201cWhy Learn Language-XYZ?\u201d. I talked about Prolog and Lisp earlier. The present article is on C++. Once you have gained reasonable proficiency with Prolog and Lisp, you are ready to learn C++! In my view, C++ is a complex\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2736,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/03\/19\/book-review-introducing-blockchain-with-lisp\/","url_meta":{"origin":1496,"position":4},"title":"Book Review: Introducing Blockchain with Lisp","author":"admin","date":"March 19, 2022","format":false,"excerpt":"Title: Introducing Blockchain with Lisp: Implement and Extend Blockchains with the Racket Language Author: Boro Sitnikovski Publisher: Apress Year: 2021 Blockchains are a hot topic these days and interestingly, I am getting involved in a project that uses Blockchain. Languages such as C++, Java, Go and Node.js are commonly used\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/03\/Blockchain-Book-300x251.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2915,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/09\/18\/book-review-embracing-modern-c-safely\/","url_meta":{"origin":1496,"position":5},"title":"Book Review: Embracing Modern C++ Safely","author":"admin","date":"September 18, 2022","format":false,"excerpt":"Title: Embracing Modern C++ Safely Authors: John Laos, Vittorio Romeo, Rostislav Khlebnikov, and Alisdair Meredith Publisher: Pearson Education, Inc. Year: 2022 C++ is a complex language. Fortunately, we have several good books (and other online material) for programmers at various levels. A few weeks ago, I had reviewed and recommended\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/09\/Book2-235x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=1496"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1496\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=1496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=1496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=1496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}