16

I realised I have a massive knowledge gap when it comes to multi-threaded applications and concurrent programming. I've covered some basics in the past, but most of it seems to be gone from my mind, and it is definitely a field that I want, and need, to be more knowledgeable about.

What are the best resources for learning about building concurrent applications? I'm a very practical oriented person, so if said book contains concrete examples the better, but I'm open to suggestions. I personally prefer to work in pseudocode or C++, and a slant toward game development would be best, but not required.

1
  • You prefer to "work in pseudocode"? I hope that works for you! :)
    – logc
    Commented Apr 17, 2015 at 10:49

5 Answers 5

6

These are the books I have found useful lately:

Java Concurrency in Practice - by the author of much of Java's concurrency utils. Somewhat Java-specific, but very clear and informative about the dangers and pitfalls of threads.

The Art of Concurrency - not a scintillating theoretical treatise as the title suggests, in fact a rather folksy and down-to-earth compendium of useful advice and examples.

Programming Concurrency on the JVM - This one actually is a scintillating theoretical treatise, but very, very readable and insightful. If you need to know what STM or actors are, what their strengths and weaknesses are and why, this book will tell you.

There are many dedicated utility libraries such as the Intel Threading Building Blocks or Apple's Grand Central Station - these generally have their own dedicated manuals, which are usually quite good, and anyway are mandatory reading if you want to do something big with them.

4

I have found this free threading resource put up by Joe Albahari excellent ...

Threading in C#

Its slanted towards C# but the concepts are entirely applicable to other languages. He also provides the tutorial as a PDF download in english and several other languages. I would recommend it due to the combination of example code, step by step explanations of the code and excellent sequence and state diagrams accompanying the examples.

The tutorial is in five parts:

Its available in book form here: C# 4.0 in a Nutshell (chapters 23 and 24)

1
  • 1
    +1, this is my usual "go-to" reference for threading/concurrency/parallelism in .NET Commented Apr 16, 2012 at 4:58
4

There are many concurrency models so you'd better have a good idea about all before you decide which one to pick. For that, I recommend the book Seven Concurrency Models in Seven Weeks: When Threads Unravel. Check the reviews and the TOC and you can see why this is a good book. And it is also recent (2014).

1

There are now threading facilities in the C++ standard. So if you want to learn in C++, I suggest reading a simple review of the new language feature before heading over to a generic threading tutorial. Then go back and review the standard in more detail later.

In practice, threading is one of those things that most people think they understand, but don't. I went to a talk from a static analysis researcher who identified race conditions in an IBM research database (Java), in a linux filesystem (C), and in some other pretty high-profile projects. Some of the projects were written by respected experts in concurrency and threading. Be aware that making thread-safe code is difficult and that the knowledge gap is not exclusive to those who recognize it in themselves.

Though it will not directly help you in game programming, I would recommend looking at some MPI tutorials (sorry, no specific recommendations). While it seems difficult to write correct concurrent code with threads, it seems rather easy to do it with message passing. Indirectly, the hope is that exploring different concurrency models will help your own thought process on structuring your code to be thread-safe.

1

To learn about concurrency, use a language that was designed for concurrency. Golang is a good choice since it has built-in support for concurrency and a C-like syntax which makes the language easy to learn for most programmers.

It has message passing, mutexes etc which cover almost all of your concurrency needs and which have more complicated equivalents in other languages.

For example, receiving an int from another thread into variable a using MPI in C:

MPI_Recv(&a, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);

Receiving an int into variable a from another (user) thread in go:

a := <-c

To learn go in practice, check out the go tour, where you can write, compile and run go code in your browser.

tour.golang.org

To skip to the concurrency part

http://tour.golang.org/concurrency/1

My former professor held a very popular short course for first year CS students on the topic of concurrency. For a quick, but thorough, introduction to what concurrency is, I definitely recommend reading the this.

Fundamentals of concurrent programming

Not the answer you're looking for? Browse other questions tagged or ask your own question.