The Hamburger Theory of Threads and Processes

You’re busy making hamburgers and suddenly you get lots of customers. You want to scale your service to take care of more customers more quickly.
Threads: all of your workers share a single set of tools, utensils, and the same workspace. One puts mustard on the spreader, turns to grab the bun, and finds that someone else has put ketchup on there while he was turning. So you come up with complex rules about who must ask permission, under what circumstances, for grabbing what tools. Sometimes worker A is waiting for worker B to put down the knife, while B waits for A to put down the cheese, and they end up waiting forever.
Processes: each worker gets his own tools, utensils, and work space. Any sharing is explicit: worker A must intentionally pass the utensil to worker B.
More tools are used with processes, so in some sense it’s less efficient. But the rules are much simpler.
If the tools and utensils are very large and valuable, perhaps threads will work. Picture lots of bees each working on a piece of the beehive.
When the tools are small their duplication is less wasteful. The simplicity of the rules makes it easy for you to get your system going, add new items to the menu, and spend a lot less time worrying about your workers waiting for somebody else to put down the cheese.
Photo by JustABigGeek.
Manage your expenses via Email, SMS, iPhone, Twitter, Voice (Call and say your expense), IM (Yahoo, AIM, MSN), or Web.
Comments(2)
Ah, another addition to your theory that everything can be illustrated with a hamburger metaphor. Excellent.
This is interesting. Of course, most kitchens do not have dozens of cooks and they do not just cook hamburgers. You typically have one cook and a few assistants. However, restaurants work pretty much independently to serve the population. You have chains, of course… like McDonald’s, but they are managed in a pretty decentralized way.
So, I guess it is a matter of scale. If you look at a problem from a distance, you can scale out by sharing-nothing processing. If you focus on a narrow problem, you often find it hard not to share.
Unix is kind of like that. We have utilities which may be threaded. However, we solve most problems by using several utilities, each running in a separate process.
In some sense, there is really two levels of programming. One were processes are better, and one where threads are better. Most people do “coarse grain” programming however, and they are better served with processes.