File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes C / C++ and the fly likes  C++ Concurrency in Action book question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark " C++ Concurrency in Action book question" Watch " C++ Concurrency in Action book question" New topic
Author

C++ Concurrency in Action book question

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 249
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

Joined: Jun 10, 2011
Posts: 57
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.


Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/
just::thread C++11 thread library http://www.stdthread.co.uk
Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
 
Consider Paul's rocket mass heater.
 
subject: C++ Concurrency in Action book question