Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

If you have to explain the concept of multi-threading to a seven year old kid how would you do it? I recently got this question in an interview. I came up with a story using jobs (the task to be done) and workers (the threads) but it was not entirely convincing (considering the kid is too young).

If you were asked to describe this, how would you do it?

share

locked by maple_shaft May 6 at 13:42

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

55  
I would ask the interviewer if he/she was planning on hiring any 7 year old children. –  Craige Mar 3 '11 at 18:30
14  
I would have Punched the Interviewer in the Face. –  Morons Mar 3 '11 at 18:36
11  
It's probably to test that you know the subject well enough to teach it to someone who has absolutely no knowledge of the subject. –  FrustratedWithFormsDesigner Mar 3 '11 at 18:36
6  
@Morons First of all, that's a bit violent. Second of all, are your Words Capitalized because of any Special Meaning? –  NickC Mar 3 '11 at 18:40
11  
@FrustratedWithFormsDesigner Well, it's bloody stupid. Can you explain complex numbers to someone who doesn't know how to count? No? You're rubbish at complex numbers then. –  biziclop Mar 3 '11 at 19:14
show 15 more comments

19 Answers

up vote 36 down vote accepted

Describe what it is, just leave out the technical terms except for definitions:

  1. You have five jobs to do. You need to start working on all of them right now.
  2. Each job is a thread.
  3. You are the processor.
  4. Spend a little bit of time working on each job and then move to the next one, making sure you give attention to all of them.
  5. If you have more people, a job can only be worked on by one person at a time.
  6. Since each person can work on a different job, more people can get all the work done faster, if you have more than one job.
share
15  
I think the only thing I'd add is maybe change "jobs" to "games" or playing with toys or doing chores or homework. –  bethlakshmi Mar 3 '11 at 18:39
1  
@el fuser You seem to assume I don't know 7 year olds, and you give no justification for your statement. –  NickC Mar 3 '11 at 22:46
show 8 more comments

Hey Kid. Have you ever walked and chewed gum at the same time while thinking about Pokemon? That's your brain multi-threading.

share
1  
That's your brain's peripherals being able to act relatively independently. It's (almost) like your brain using DMA. –  Nick T Mar 4 '11 at 1:32
show 3 more comments

Relate it to something they can easily understand. Cars on a road.

Think of a single lane road. With 12 cars on it, they drive one after another. And only one car can finish at the same time, and a faster car, can't pass the slower ones.

But, with multi-threading, it's like all those cars are driving on a wide road with four lanes. The faster cars can go past the slower ones.

Edit: and, if they aren't careful, they can crash into each other...

share
4  
If multi-threading is a road, then it's one where when one car is driving, the other isn't moving at all - not following behind it... –  NickC Mar 3 '11 at 20:51
show 1 more comment

I would explain it like doing the laundry.

You have 3 loads of laundry, and one washer and one dryer.

The way everyone does laundry is to move the first load into the dryer than put the next load for washing.

Any kid would understand that waiting for the first load to dry before starting washing the second load would take more time.

You could even take it a step further by explaining if you have more washers and dryers (like at a laundromat), you can do the loads faster.

share
2  
Additionally you can't dry the laundry until a load has gone through the washer, so you can also describe blocking –  zzzzBov Mar 3 '11 at 20:33
show 1 more comment

Cooking a meal with several dishes on a small stove. You have two burners (i.e. processors or cores) and four dishes (threads) to cook. So only a maximum of two dishes can be cooked (run) at a time. Different dishes have different cooking times. The cook (the OS) has to juggle all of this so everything gets cooked in time for dinner.

share
add comment

A circus juggler starting with two balls and gradually adding more and more balls to his or her act.

share
show 1 more comment

In my experience 7 year olds have no problems with the concept of different things going on on the same time, which is witnessed by the various programming toolkits designed for kids. Notably the Lego kits, but also the Scratch system.

Perhaps the interviewer was simply trying to find a new angle on asking you something unexpected.

share
add comment

"I need you to carry two glasses from the kitchen to the table. (They run, carrying a glass in each hand.) Now, please do it again, but only use one hand."

share
add comment

Some of these answers are mind-blowing... I think I might be the only one here that knows 7 year olds???

So, Johnny... Multi-threading is similar to what happens when it's clean up time at school. All of your class needs to clean up after the end of the day... Each kid is basically a thread... picking up toys is the task, and the toy box is a shared resource.

Overall I think punching the interviewer in the face is a better answer.

share
show 2 more comments

Multi thread, it's like having many things to do at a time, and do them little by little.

Hey the young curious guy, every day you must eat, play & sleep; right? But why don't you eat once... take a lot until you can't take more, then sleep all the time you need, then just play & play interesting games?

Well, you can't do that, because if you don't eat, you'll get hungry, no matter how much you got in the previous meal. If you don't sleep, you'll be tired and can't play with your friends. Understood? There's several things that need to be done, but we can't do them at once. We eat breakfast, play game, take lunch, play games again,... and says "good night" at last.

That's also the way a computer work: they play the music a little, then switch to the picture which you are drawing, then switch again to play music. But the time it took to do all of those things a thousand time is just a wink of eye, so you can't see it.

share
add comment

You have a set of 6 tasks you have to do:

  • do your homework
  • clean up your room
  • do the shopping
  • pick the apples in the garden
  • wash the dishes
  • sweep the porch

Each task takes 1 hour to do. You have 2 brothers.

  • If you don't use multitasking, it means you have to do all the work by yourself. It will take you 6 hours (if you start at 12:00, all tasks will be completed at 18:00).
  • If you use multitasking, it means you can give some tasks to your brothers. If you all start working at the same time, you will finish all the tasks sooner. In this case, all 3 of you will do 2 tasks each, which will take 2 hours (if you all start at 12:00, all tasks will be completed at 14:00!).
share
add comment

You've got one joystick/game controller.

There are 4 kids. Each kid takes a turn playing each level while the others rest. Using teamwork, they eventually reach level 255 *.

While each kid is playing, he's also eating from the bag of chips that only the current player is allowed to eat from.

*Then the game crashes. ;)


"Why don't you buy 3 more controllers?"

Well, those are multiple processors!

share
add comment

Art class (Multi-threaded application)

Since there can be no class without a teacher, you need a teacher (main thread). When you get to class you sit down and the teacher accounts for everybody and assigns the class to paint pictures for the day.

The teacher assigns all the students for the day to start painting (thread initialization and assignment).

Because the school only has so many paints, everybody is going to have to share colors with each other (paints represent memory).

Lets say you're painting a dragon and you want to give it crazy red eyes but somebody else is using the red paint. You can't just go over and take the paint for yourself because then nobody else would be able to use it. Instead, what you do is you politely ask to share (resource locking) the paint. You use a little, then pass it along. You may have to wait a bit to get it back but it allows everybody who needs it to get some without a paint fight (race conditions).

At the end of the class the teacher dismisses the class (thread joining).


Gaming (Multi-process application)

Playing a card game with friends (or equivalent game with collectibles):

Lets say you get together with your friends (processes) after school. There are no teachers around to nobody is there to tell you what to do.

Everybody is gets together to play games (multi-process or multi-layered application).

You think hard about how you can use your cards to beat your opponents (internal processing) and you try to share ideas with your partner when you come up with an idea (message passing).

If you get really good you may join a club:

Leader (executive program) Members (subprograms)

If the club gets really good they may come up with a special way (API) to communicate with each other to help strategize better.


I chose not to mention multiple processors/cores here because the abstraction gets pretty complicated (and context switching is still transparent to most applications). I could probably start by saying that every team in the game represents a separate processor/core and most games still suck because they only allow a few teams to play together in a game. The future may look something more like an MMORPG where many people can play together in a game on many different teams.

Trying to develop a kids metaphor for a distributive processing system on a many core computer or many host network would be pretty interesting to play with but that's not what the Op asked for.


Note:

Message passing above is a reference to the many forms of communication that programs use to talk to each other. Like people, applications have many ways to talk to each other. Writing is like Piping serialized data, talking is like networking, whispering is like networking over an encrypted connection, databases are like a score card (finite structure with well defined data), and using MSMQ is like tapping morse code by bashing your head against a solid surface.

Most other forms of communication beyond that blur together too much for me to consider them indistinguishable.

Aside:

If you've ever played an online game like Halo, the people who join groups (or become pro players) usually have a shortened language to give call outs to direct each other where the other team's players are and what they're using. It's really obnoxious if you don't know the call outs but it's surprisingly effective during game play.

It's interesting how, even though most people that live within a given culture speak a common language but within that culture people develop shorter succinct domain languages that are optimized to handle specific tasks. In computing I'd compare that to an API.

share
add comment

Use a widely adopted model: the dining philosophers.

5 Philosophers eating their pasta dinner.

5 Forks available around the table.

Each philosopher needs two forks to eat.

Some eat. Some philosophize while waiting.

share
2  
Philosphers eat with two forks? Man, they're even stranger than I thought! :P This story makes more sense with chopsticks instead of forks... –  FrustratedWithFormsDesigner Mar 3 '11 at 19:02
4  
@Frustrated, that is why they need to think so much. –  user1249 Mar 3 '11 at 19:04
4  
I like the chopsticks analogy better. You definitely need two chopsticks to eat. You don't really need two forks. The forks thing actually confuses the issue. Especially since forking is a key term in multiprocessing. –  Paul Sasik Mar 4 '11 at 1:04
show 4 more comments

Suppose you're (the kid) bouncing a ball on your head. After every bounce, you're counting it, i.e., number of bounces. Also after every bounce you're saying the letters from alphabet (A, B, C, ...)

Kid, you're multithreading.

share
add comment

Spinning plates is a good example. Think of those magician people who take some plates and get them spinning all at the same time. The magician is constantly switching between plates to ensure they all stay spinning.

share
add comment

A computer can really only work on one thing at a time, but it can do things very quickly. (I'm leaving out multi-core processing for simplicity.) But what if you want to listen to music and play a game at the same time? The computer (very rapidly) switches between handling the music and handling the game.

share
show 1 more comment

Our local playground has a triple slide and a single slide. Threading is like the triple slide, 3 kids can slide down simultaneously. But on the single slide two kids have to wait at the top for the first kid to go down the slide.

Was part of the job description reporting to the CFO?

share
add comment

Two kids in a playground sharing (fighting over) limited resources, say the required lego pieces from a small box to make their favorite robots.

share
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.