Threads considered harmful

In the past month I’ve seen at least 3 messages on the development email lists at work asking questions about developing multi-threaded applications. From a software engineering standpoint, this troubles me.

I’ve always thought that multi-threaded apps in C/C++ are simply too difficult for most engineers to understand. There’s too much non-determinism, too many race conditions, and too few language-level constructs to keep yourself from screwing up.

This isn’t to say that some engineers can’t figure it out, it’s just that most engineers can’t. I’ll borrow a diagram from Ousterhout to illustrate this point:

What's Wrong With Threads?

John Ousterhout, Why Threads Are a Bad Idea (for most purposes), 1996. PDF slides from USENIX 1996 talk (local mirror).

I’ve been reading The Art of UNIX Programming by Eric Raymond over the past few weeks and it appears that he agrees with me. He avoids the Dijkstra-esque pun on threads being harmful and instead perfers the equally-provoking title Threads — Threat or Menace?

My attitude about threads Java is different because the language has supported the concept of threads since day one. It’s still tricky to do threads correctly in Java, but not as painful as it is in C++.

3 thoughts on “Threads considered harmful

Comments are closed.