• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

C++ Concurrency in Action book question

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How will the latest C++ concurrency standard handle issues such as deadlock, livelock, fairness, starvation, race condition?
Do the C++ Concurrency in Action book has examples for the above concurrency issues?
 
author
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

albert kao wrote:How will the latest C++ concurrency standard handle issues such as deadlock, livelock, fairness, starvation, race condition?



To a large extent these issues are all about the correctness of your code rather than anything that the library can handle. However, the library does provide one direct facility that can help: std::lock(). This is a function template that takes a set of mutexes (or wrappers such as std::unique_lock<>) and locks all of them in one go, without risk of deadlock due to lock ordering issues. This allows you to lock pairs (or triplets) of mutexes in different threads without having to worry about the order of the locks causing deadlock.

albert kao wrote:Do the C++ Concurrency in Action book has examples for the above concurrency issues?



Yes. Concurrency-related bugs are covered in chapter 10, but there are also examples given throughout the book. Chapter 3 discusses locks and deadlocks, and gives examples for std::lock() usage, as well as code for a simple hierarchical mutex class that helps avoid deadlock by enforcing lock ordering.
 
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic