Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

C++ Concurrency in Action book question

 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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?
 
Anthony Aj Williams
author
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic