21

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?

Nicole
  • 28,111
  • 12
  • 95
  • 143
Vinoth Kumar C M
  • 15,455
  • 23
  • 57
  • 86
  • 55
    I would ask the interviewer if he/she was planning on hiring any 7 year old children. – Craige Mar 03 '11 at 18:30
  • I think these type of questions are common. – Vinoth Kumar C M Mar 03 '11 at 18:31
  • 14
    I would have Punched the Interviewer in the Face. – Morons Mar 03 '11 at 18:36
  • 1
    The question isn't so much the how but the why. – biziclop Mar 03 '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 03 '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? – Nicole Mar 03 '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 03 '11 at 19:14
  • @biziclop: In that case, you first teach them to count. ;) Unless you can find an analogy for complex numbers that doesn't actually require an understanding of counting (not that I'm saying that is easy or even possible, but that's the general approach). – FrustratedWithFormsDesigner Mar 03 '11 at 19:16
  • 1
    @FrustratedWithFormsDesigner Well, that would be my answer too: first I'd teach them how computers work and what a program is, then multithreading. I somehow doubt they would've liked my answer though. :) – biziclop Mar 03 '11 at 20:02
  • 1
    Explaining 'the facts of life' to a 7 year old would be much easier than this. – TeaDrinkingGeek Mar 03 '11 at 20:06
  • 1
    @biziclop: With reference to complex numbers, you might want to look at Richard Feynman's book "Q.E.D" (on quantum electrodynamics) to see how he finessed the use of complex numbers. – David Thornley Mar 03 '11 at 20:08
  • 1
    @biziclop, I have to say if an interviewee of mine displayed a hostile attitude, or even a pretentitious "this isn't children's work" attitude toward the question, then it did a brilliant job helping me filter a candidate. – Nicole Mar 03 '11 at 21:42
  • @Renesis That's not what I meant. Multithreading is just too large and complex as a subject to be explained in one go. Bits of multithreading, like time slicing or message passing, even synchronization can be, but not with the same metaphor. Knowing myself, I would probably simply ask "Why?" anyway. :) – biziclop Mar 03 '11 at 22:10
  • 1
    @biziclop - is it fair to think that the interviewer might not be judging your knowledge of multithreading at all? – Nicole Mar 04 '11 at 00:19
  • @Renesis I hope so. Like I said, if they want to, that's just mental. – biziclop Mar 04 '11 at 00:29
  • @TeaDrinkingGeek Everyone knows that the fact-or-s are 6 and 9. – Mateen Ulhaq Mar 04 '11 at 01:01
  • Why do all these answerers assume that 7 year olds only like Pokemon and philosophers? What happened to math, science, computers, and books? (Not that I have anything against philosophers.) – Mateen Ulhaq Mar 04 '11 at 01:22
  • 1
    Excellent question. If you can't explain it to a 7 y.o. your just not doing it right! – Anonymous Type Mar 04 '11 at 02:24
  • 4
    It'd probably be easier to explain it to a 7 year old than someone from human resources. – Andrew Grimm Mar 04 '11 at 05:56
  • How would I explain it to a seven year old? With another five years of primary school, five of high school, and three or four of university. Of course, I'd probably hire some teachers and lecturers to help. – detly Mar 04 '11 at 06:39

19 Answers19

35

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.
Nicole
  • 28,111
  • 12
  • 95
  • 143
  • 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 03 '11 at 18:39
  • Then if you have 'the processor' 'keep notes' when they're working on a job, you can explain cache and cache coherency in a multiple processor env – Steven Evers Mar 03 '11 at 19:13
  • Good description, but knowing 7 year olds, this won't fly. – red-dirt Mar 03 '11 at 22:36
  • @el fuser I *am* a 7 year old! or atlest i ac lke 1 hahahahahaha – Mateen Ulhaq Mar 04 '11 at 01:06
  • @bethlakshmi, your assuming that at 7 most kids are still playing games and haven't gone out and got productive jobs yet? come on! – Anonymous Type Mar 04 '11 at 02:25
  • I don't see how this explains multithreading in specific. It explains the general concept, which also includes multiPROCESS solutions. – dietbuddha Mar 04 '11 at 03:20
  • @dietbuddha - that's a fair point. I'd be interested to know, if you were drawing an analogy at a 2nd grade level, can you think of a way to separate the two? – Nicole Mar 04 '11 at 04:57
  • @Renesis - I don't think you can distinguish the 2. The analogy that's needed to convey the idea is going to have to be so basic as to lose most of the meaning of what multithreading is. I would say you cannot explain multithreading at that level. You can provide a general idea, but it isn't multithreading. – dietbuddha Mar 04 '11 at 18:11
  • @dietbuddha Maybe if you had their concentration long enough to illustrate the first part, then you could illustrate processes by breaking people up into teams. – Nicole Mar 04 '11 at 18:17
22

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

Adam Crossland
  • 9,688
  • 2
  • 35
  • 46
  • 1
    That's your brain's peripherals being able to act relatively independently. It's (almost) like your brain using DMA. – Nick T Mar 04 '11 at 01:32
  • @nick T, more like cloud computing with only no source code access to the components. Even the person chewing the gum has no idea how they are actually performing the action. – Anonymous Type Mar 04 '11 at 02:27
  • @Ano, your last statement seems to reinforce my peripheral analogy. The peripheral does stuff without the CPU delving into the minutiae, just simply delegating it. I guess you could also say it's like cloud computing, but that's on a much larger scale; DMA and peripherals are fairly low-level. – Nick T Mar 04 '11 at 03:31
  • really? I would have thought playing pokemon (higher order problem solving) would have definately required user mode memory and the use of a higher level programming language, but perhaps something like masticulating could be DMA. – Anonymous Type Mar 04 '11 at 03:35
10

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...

CaffGeek
  • 8,033
  • 5
  • 32
  • 38
  • 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... – Nicole Mar 03 '11 at 20:51
  • @Renesis, good point, I suppose I could change the example to a narrow bridge that only one car can cross at a time because two cars would be two heavy... – CaffGeek Mar 03 '11 at 21:27
10

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.

Tyanna
  • 9,528
  • 1
  • 34
  • 54
  • 2
    Additionally you can't dry the laundry until a load has gone through the washer, so you can also describe blocking – zzzzBov Mar 03 '11 at 20:33
  • I almost gave you a +1 but then I realised that no kid in their right mind would follow this explanation. For starters you used something extremely boring (from the kids perspective not mine) which is a chore. As soon as you say the word laundry their mind switches off, they literally would only hear the first 7 words. – Anonymous Type Mar 04 '11 at 03:37
6

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.

tcrosley
  • 9,541
  • 1
  • 25
  • 41
3

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

Yuriy Zubarev
  • 2,653
  • 1
  • 15
  • 15
2

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.

2

"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."

J.K.
  • 13,063
  • 1
  • 40
  • 56
2

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.

red-dirt
  • 3,668
  • 1
  • 22
  • 26
  • whoever marked this -1 is kidding themselves. seriously grow a sense of humour. It's a ridiculous question that should be treated in that light. – Anonymous Type Mar 04 '11 at 02:32
  • This is probably one of the best answers hear so far. It takes the concept and puts it *in terms the listener understands* - even if the listener has no idea how to *code* a multithreaded app, they will now understand the basic idea. – FrustratedWithFormsDesigner Mar 04 '11 at 14:35
2

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.

Hoàng Long
  • 856
  • 1
  • 12
  • 19
1

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!).
user19248
  • 101
  • 2
0

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!

Mateen Ulhaq
  • 968
  • 3
  • 11
  • 21
0

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.

Evan Plaice
  • 5,725
  • 2
  • 24
  • 34
-1

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.

S.Lott
  • 45,264
  • 6
  • 90
  • 154
  • 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 03 '11 at 19:02
  • 4
    @Frustrated, that is why they need to think so much. –  Mar 03 '11 at 19:04
  • I don't think replacing chopsticks with forks works to well. :) – Tyanna Mar 03 '11 at 20:20
  • 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 04 '11 at 01:04
  • .. and then your stuck explaining what a philosopher is. And of cause they will ask why they need two forks (which is kinda dumb from a 7yo's perspective) and why of cause anyone would wait before eating! – Anonymous Type Mar 04 '11 at 03:39
  • This is deadlock, which I would put past the understanding of the average 17 year old, let alone 7 year old! – Nicole Mar 04 '11 at 04:54
  • @Renesis: Most 7 year old understand sharing. And interrupts. And -- if you want one of the many solutions -- you can introduce someone who assures that only 4 philosophers are seated at one time. There are many solutions to this classical problem in concurrency. Most 7-year-olds can propose some kind of sharing solution. Ask one. – S.Lott Mar 04 '11 at 10:52
-1

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.

Donotalo
  • 1,219
  • 1
  • 12
  • 19
-1

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.

Ian
  • 5,462
  • 22
  • 26
-2

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.

Maxpm
  • 3,146
  • 1
  • 25
  • 34
-2

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?

jqa
  • 1,410
  • 10
  • 13
-3

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

hotpaw2
  • 7,938
  • 4
  • 21
  • 47