Tuesday, September 20, 2005

Thoughts on Threading

So this week I've been thinking a lot about threading.

Specifically I've been thinking about large, complex multithreaded servers that are difficult to write, to test, and most importantly to modify later on, especially if you are not the person who actually designed and implemented them in the first place.

Among the better papers I've seen on the subject is "Reasoning about SMP in FreeBSD", by Jeffrey Hsu, who did a lot of work on locking the FreeBSD network stack as part of it's SMP project. Interestingly enough, Hsu is now working on DragonFlyBSD, which has taken a rather different approach to its multithreading than FreeBSD did. Makes you wonder if the more traditional techniques (fine grained mutexing, a-la the Solaris kernel) used in FreeBSD are really the right way to go...

Go read the paper, it's good.

Anyway, the big idea of that paper is that to effectively think about a multithreaded system you really need to understand what it's doing. You can't effectively add locking to one part of the system without totally understanding all the interactions it has with the rest of the system. You really need to see the big picture in order to know how to make the individual decisions.

I've been having trouble seeing the big picture, that's the problem.