February 16, 2015

Concurrency in C# Cookbook review

book cover
Concurrency is a topic that many programmers, even some senior ones, still didn't get right. These days, it's mostly misconceptions about asynchronous programming, but apart from that, not many people heard about reactive programming (Rx) or used TPL Dataflow.

What I like about the book is that it covers all different types of concurrency and clearly explains when would you use one in favor of the other. It's also easy to skip what you already know thanks to its cookbook format.

Follows a short extract from the first chapter "Concurrency: An Overview" that is in my opinion a very good start to this topic and every single programmer should know even if he/she don't use it.

Concurrency
    Doing more than one thing at a time.
Multithreading
    A form of concurrency that uses multiple threads of execution.
Parallel Processing
    Doing lots of work by dividing it up among multiple threads that run concurrently.
Asynchronous Programming
    A form of concurrency that uses futures or callbacks to avoid unnecessary threads.
Reactive Programming
    A declarative style of programming where the application reacts to events.

The book is all about introducing you to all these topics by providing you with short and clean code samples with explanations. Then there are chapters that describe how to test concurrent code, how to interop between different styles, how it fits into OOP world and few other. Amongst them, I particularly enjoyed a chapter called "Collections" which describes various types of concurrency-friendly collections. Have you heard about immutable or blocking collections yet? I certainly had not before I read the book. Now I even know which one to choose when dealing with concurrency in my code.

I recommend this book to everyone who had not chance to use threading much to get a nice high-level view on concurrency, but also to everyone who started with threads in early .NET Framework versions and still use it these days. Basically, you should not need to call new Thread(); in your code anymore.

Head to the author's blog for more.

No comments:

Post a Comment