Threads Considered Harmful

So says Roman Shaposhnik, frequently referencing Edward E. Lee’s “The Problem with Threads“. I largely agree; threads are not a mechanism that can be effectively used by mere mortals, and we are all, after all, mere mortals. The default everything-is-shared setup seems the exact opposite of what’s needed: default of nothing-is-shared-unless-explicitly-declared.

The sweet spot of scalable Web apps these days is multi-process with explicit sharing via shared-memory (eg. memcached) or messaging. I don’t know if there’s a whole lot wrong with that. We may need easier or more integrated mechanisms for invoking and using the shared memory/messaging, but otherwise it’s a nice model – it’s well understood, scales well to multiple CPUs, and is reliable.

I remember a paper from back in grad school (Joe Pasquale’s operating systems class) that delved into the relative overhead of processes versus threads, making the point that the difference is not that large in modern operating systems. Anybody know of the relative overhead of processes versus, say, Java threads in Linux?

I really need to play more with Erlang and company, there may be interesting insights or programming models there…

1 Comment so far

  1. Matthias Hoermann on August 5th, 2007

    In Linux posix threads and processes are basically the same, processes just have an additional flag set to share the memory and a few other things. The overhead for processes is not a big deal.

    Green threads (threads implemented completely inside one userspace process) like the ones used in the Erlang runtime system have a lower overhead (no system calls needed) but they are harder to implement and not all implementations of green threads are as good as the one in the erlang runtime system.

Leave a Reply