This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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?
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.