Before I begin, a brief bit of technical background: A while back, Scott Hanselman posted two sets of questions that he feels are useful when interviewing: ASP.NET Interview Questions What Great .NET Developers Ought to Know As Scott says, "knowing groking these questions may not make you a good or bad developer, but it WILL save you time when problems arise. " Even if they weren't in some ways instrumental to your development path if you are a .NET developer, the knowledge will still come in handy. And now a brief bit of *other* background: My grandmother is part of the readership of this blog(*),but is not necessarily all that technically minded. She is a wizard at using her DVD player, and I have no doubt that she could pick up any topic if she so chose since she is a brilliant woman; however, she is not a programmer, and thus a discussion of processes vs. threads would fall on deaf ears. And what if my grandmother wanted to work at Corillian one day? Would she be able to get through a Scott Hanselman interview? That being said, this is the first of a series for my grandmother:
Let’s pretend that we have a nasty gang called the Narayans (no relation to any living beings...honestly), who have overrun the Rockarts neighborhood and are now slowly converting the homes of the Rockarts neighborhood into drug factories. Having taken over the neighborhood, they also have free access to most of the banks, grocery stores, and other local businesses in the neighborhood. Each member of the Narayan gang wears the same crusted-over hoodie as a gang symbol. To tell each member apart, they have a name and number on the back of their hoodie.
The police don’t really care about the Rockarts neighborhood all that much - in fact, they never really liked the Rockarts neighborhood in the first place!! Thus, they don’t care if it gets run over by the Narayans. However, to protect the city from gang warfare, they’ve erected a barrier between the Rockarts neighborhood and the next one over, so as to prevent the Narayans and the rival gang, the Fedirkos from having a shoot out.
Now, the Narayans are a pretty organized gang; they have a detailed report that describes the Rockarts neighborhood and details the plan to convert all the homes into drug dens. It also has a tally of all of the stores that the Narayans now run, as well as information on every outsider in contact with the Narayan gang and their varying levels of access to different areas of the neighborhood.
You might think being part of the Narayans gives some decent benefits (except for wearing that dirty hoodie) and you’d be right. Each member gets a storage locker in the neighborhood, and a blackberry that automatically updates with the state of the city as a whole. Each member operates either overtly or undercover depending on the situation. Overtly members carry a rocket launcher, while undercover members carry a pen knife.
Now, onto processes and threads.
"Windows Internals" (an excellent book that every developer should read at some point) describes a process as the virtual address space and control information necessary for the execution of a set of thread objects, but you don’t care about stuffy definitions in awesome thought-provoking books! You care about the Narayans!! So let’s rewrite this definition in terms of the gang.
Process: the neighborhood limits (virtual address space) and detailed report (control information) necessary for individual gang members to operate (execution of a set of thread objects).
"Windows Internals" describes a process as containing:
Likewise, in our analogy, a process contains:
Now, a thread, on the other hand, is described as being an entity *within* a process that Windows schedules for execution.
Thread: An entity within a process that Windows schedules for execution (in our case, a Narayan gang member).
A Windows thread includes the following essential components:
In our case, reworking this to describe a Narayan gang member:
So, a process is actually a larger, more encompassing set of information, of which a thread (or Narayan gang member) is only a part. Threads can only operate within their process and on the space available to their process - they cannot operate on memory that is exclusive to another process (hence, why the Narayans can't operate in the Fedirko gang territory).
Don’t worry, Granny! One day we’ll get you to that Corillian interview!
(*) My grandmother does not have a computer; however, she reads this blog by my printing out the entries and passing them along. I haven’t asked her opinion of the MSDN conference but I know she agrees that Biztalk needed better representation!
Other entries in the "My grandmother and" series:
Remember Me