Author: Paul Butcher
Publisher: Pragmatic Programmers
Audience: Experienced programmers
Reviewer: Mike James
The subtitle tells it all "When Threads Unravel".
Concurrency is not an easy topic. Just when you think you understand it there seems to be another way to make a mess of it just waiting to be discovered.
This isn't a traditional academic book on the subject. It is an attempt to explain concurrency in a reasonably practical way. Don't expect the book to give you definitive answers it is more about making you aware of the problems and how to avoid them.
The introduction explains what concurrency is and contrasts the idea os asynchronous and parallel execution. It also introduces the seven models to be examined in the the book:
- Thread and locks
- Functional programming
- The Clojure Way - separating identity and state
- Communicating Sequential Processes (CSP)
- Data parallelism
- Lambda Architecture
Chapter 2 starts with on this list with threads and locks and it is a potted introduction to the basic approach to concurrency. It is some of what you would learn in a computer science course on the topic including the well known dining philosopher's problem, deadlock and all manner of locking schemes. The discussion is good and so are the examples. Occasionally the explanations miss some of the questions that every beginner has such as why do we lock on this so often and how do you organize which objects to use as locks.
Chapter 3 is a look at functional programming and it is the first of a number of chapters on Clojure, a Lisp-like language that runs on the JVM. This is by no means a Clojure book, but you do have to read and follow the examples given in the language. It is used to make a point. After a good explanation of why functional programming is a good idea and how it makes concurrency easy because of immutable data structures and pure functions we don't really get to grips with why this is. Instead we learn about how to implement functional parallelism with a map reduce type approach. The next chapter follows on with a deeper look at Clojure and the Agents/Transactional memory approach.
Chapter 5 looks at another approach to concurrency this time Actors in Elixir, which isn't the most commonly used language in the world but is difficult to beat when it comes to this job.
Chapter 6 uses Go as an example of communicating sequential processes, i.e. Go channels.
Chapter 7 introduces the use of the GPU as a general purpose parallel computer. This is just deep enough for you to start to understand. If you want to know more you will need another book on OpenCL.
The final chapter is about the Lambda architecture which is essentially Hadoop and map reduce.
This is an easy to read book on a difficult topic and for this it is welcome. It is a good introduction to seven approaches to the problem, or rather seven aspects of the problem. It isn't a book about Clojure, which you might conclude from looking at the chapter headings, but it isn't a book about pure concurrency either - different languages are used to illustrate the approaches.
Personally I would have liked more on the basic approach using locks and something on lock free algorithms. It also doesn't cover the problem of asynchronous programming and there is no mention or promises or async and await. Don't expect it to teach you all of the techniques in, say Java concurrency or how to best use locks, but it will give you a reasonable overview of the topic.
This is a good book if you want to read around the topic rather than solve a specific problem. For this it is highly recommended.
To keep up with our coverage of books for programmers, follow @bookwatchiprog on Twitter or subscribe to I Programmer's Books RSS feed for each day's new addition to Book Watch and for new reviews.