|Parallel Programming with Microsoft Visual Studio 2010 Step by Step|
Author: Donis Marshall
If you have have been afraid of venturing into the difficult and intimidating world of threads and locks then perhaps the relatively new .NET Task Parallel Library TPL is a better way. It attempts to abstract the ideas of parallel programming and package them up in ways that are easier to use. So for example, in place of threads you work with tasks and there are constructs such as the parallel for ready to automatically split an iteration up between multiple cores. The problem is that while the TPL is easy to use it isn't foolproof. You can create programs that fail because of low level locking problems. So you can't simply make use of it without understanding what it does and how it works.
This book is all about getting you to use the TPL safely and as such it does have to tell you about wider issues in parallel programing. Chapter 1 starts off with an overview of the main issues of parallelism explaining why we need to make use of it and the typical patterns of use. This is a good introduction to the subject but it stays at a fairly high level - the actual details of low level locking and similar constructs aren't dealt with.
Chapter 2 is where the practical stuff starts. Here we learn about parallel tasks the TPL way of doing threads. After a brief introduction to the ideas, we have our first step-by-steps. To be honest these aren't really necessary as step-by-steps and the mode of presentation makes you feel like you have just been dropped into kindergarten level class.
Presenting the code with some description interwoven would have been more suitable. Also the step-by-steps are a little repetitive - create two tasks and wait for them both to complete is followed by create to tasks and wait for the first one to complete. You really don't need to go over the entire construction of a a program when only a few lines change.
Later in the chapter we have a presentation of sorting methods which is easy to follow, but might come across as either naive or patronising if you already know this material - and you really should already know it.
Chapter 3 is about data parallelism which is where you use features such as the parallel for to process data with multiple threads. In many ways this is the most dangerous aspect of using the TPL because it is so easy to replace a standard for loop with a parallel for without being sure that it is safe to do so. The account does stress where things can go wrong but perhaps not enough. It then moves on to consider reduction where locking and synchronization are essential. It is at this point you might realize that standard locking patterns haven't actually been introduced in much detail and you are just expected to know what is going on. The chapter ends with a look at a map reduce type example.
Chapter 4 deals with PLINQ and after a very brief introduction to LINQ it more or less just says - add AsParallel and let the system take care of it. Actually this is more or less what happens in real life. Later there is a longer discussion of the different options and how to implement reduction.
Chapter 5 is about the new concurrent collections classes. Oddly it is only here, near the end of the book that lower level synchronization mechanisms are introduced however only Spinlock and SpinWait are described. After this we learn about concurrent stack and similar collection objects.
Chapter 6 is about customizing the way the TPL operates and it probably isn't something every programmer needs to learn about
The final chapter is about reports and debugging. Basically this is a tour of the parallel debugging and profiling features of Visual Studio.
Overall this is a good book that stops short of being a really good book. It is written in an easy to read and friendly style. Occasionally you can argue that it strays off topic but most of the time it stays focused on the TPL. If anything it doesn't provide enough background. Something on traditional locking would have been helpful and perhaps examples of how things can go wrong.
The big problem with this book is that it tries to be step-by-step when the material just doesn't need it. Where the author simply describes ideas the book works well. It could also do with an early chapter discussing how parallel is done without the help of the TPL, even though this might cause some readers to say that it has veered off topic. The TPL isn't so good that you can simply ignore low level locking and synchronization.
Not a bad book and if you are a parallel programming beginner it will more than get you started. Let's hope fore a better next edition.
|Last Updated ( Wednesday, 23 November 2011 )|