Answers.Body: <p>I would use the nursery tale of two goats across a narrow bridge. Once the first goat is on the bridge, the second one needs to wait before getting on the bridge till the first has crossed over, so as to avoid a collision. That is also why road workers use flags also called semaphores to coordinate traffic on lane closures.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-10T06:30:56.427Z
Answers.LastActivityDate: 2019-09-10T06:30:56.427Z
Answers.UserDisplayName: Kutluhan Erol
Answers.Body: <p>I think a case that hasn't been covered yet is the possibility of work being completed twice or work being lost due to a race condition. Here is an example to fill that gap:</p>
  
  <p>You have 2 groups of dogs, the "carriers" and the "pick up-ers". They are on opposite sides of a field, and in the middle is a small cup, which only one ball can fit on top of. The carriers have a pile of tennis balls, and have been trained to bring the balls to the cup. The pick up-ers have been trained to take a ball out of the cup and bring it back to their side. You are watching this happen and counting the number of balls that have been brought over by counting the dogs-with-balls-in-their-mouths that reach the pick-up-ers side.</p>
  
  <p>What happens if two carrier try and put a ball in the cup at the same time? One will fall on the ground, and won't get picked up, causing you to lose that tennis ball. Or what if two pick-up-ers try and grab the same ball and both grab it together? You'll count it as two, since two dogs-with-balls-in-their-mouths crossed the finish line, but actually only one ball has been carried.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-10T17:14:42.600Z
Answers.LastActivityDate: 2019-09-10T17:14:42.600Z
Answers.UserDisplayName: thesecretmaster
Answers.Body: <p>A lot of race conditions result from improper or unexpected interleaving of processes. Someone that age can probably understand the fable of the Turtle and the Hare. </p>
  
  <p>Give the Hare a ball with instructions to run to a table, some distance away, and leave the ball on the table and return. </p>
  
  <p>Tell the Turtle to go to the table, pick up the ball, and return with it. </p>
  
  <p>Start the two "running" at the same time. </p>
  
  <p>The Turtle has no instructions about waiting, since the <em>proper</em> interleaving is <em>obvious</em>. </p>
  
  <p>Of course, if the Turtle gets to the table first then the process fails. </p>
  
  <hr>
  
  <p>I'll note that <a href="https://en.wikipedia.org/wiki/Dining_philosophers_problem" rel="noreferrer">Dining Philosophers</a> isn't a lot more difficult than the above, but probably not accessible to a five year old. Certainly open to one a few years older, though. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-04T19:11:04.603Z
Answers.Text: How would you modify this to deal with the "sometimes" fails for race conditions?
Answers.UserDisplayName: Gypsy Spellweaver
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-04T19:12:57.917Z
Answers.Text: @GypsySpellweaver, well, sometimes the bunny does, in fact, do the right thing. And sometimes the turtle is the one who wants a nap.
Answers.UserDisplayName: Buffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-05T17:57:35.970Z
Answers.Text: I find the Turtle and Hare comparison really nice as it nicely illustrate that one actor might be “faster” than another one but might take “pauses”. About the Dining Philosophers I would definitely use it to illustrate what a deadlock might be, however I do think that the associated concepts might be a bit difficult to explain to a kid of that age (who would need two forks to eat??? ;) )
Answers.UserDisplayName: Renaud M.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-08T18:38:36.293Z
Answers.Text: @RenaudM., the dining philosophers problem makes more sense if the table is set with _chopsticks_  instead of forks.
Answers.UserDisplayName: Solomon Slow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-27T02:32:26.940Z
Answers.Text: 5 year olds love the stacking hands game, where the players interleave their hands in a stack, then each player when his hand is one the bottom of the stack pulls it out and places it on the top of the stack. The players get faster and faster until there is just crazy slapping as everyone's hands collide. That is a race condition.
Answers.UserDisplayName: pojo-guy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-04T19:05:52.627Z
Answers.LastActivityDate: 2018-10-20T23:47:02.857Z
Answers.LastEditDate: 2018-10-20T23:47:02.857Z
Answers.UserDisplayName: Buffy
Answers.Body: <p>Imagine two guys at a door. Each says, "No, you go first."  Result: deadlock.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-23T01:01:16.057Z
Answers.Text: Simplicity itself.
Answers.UserDisplayName: Gypsy Spellweaver
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-23T00:58:12.737Z
Answers.LastActivityDate: 2018-10-23T00:58:12.737Z
Answers.UserDisplayName: ncmathsadist
Answers.Body: <p>Musical chairs where one person sits on another as they are both going for one of the last chairs &#8212; this is comical, though in seriousness, clearly a less than desirable seating arrangement.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-05T10:58:03.230Z
Answers.Text: Pretty close, except that "everyone sitting" is guaranteed to fail here. Instead, have a second "process" remove a chair after the music starts. If the music stops early, everyone sits, otherwise the usual thing. Even this is a bit suspect as one of the two processes (circling, removing) will always fail.
Answers.UserDisplayName: Buffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-05T01:39:52.447Z
Answers.LastActivityDate: 2018-10-05T01:39:52.447Z
Answers.UserDisplayName: Erik Eidt
Answers.Body: <p>When there is a slide in the playground where many children want to slide, they need to queue and each one needs to check if the slide is free (i.e. if the previous child got up from the bottom of the slide) before going down. If they don't check it, they may run into one another and hurt themselves.</p>
  
  <p>That is what happened to your programs* - some where playing carelessly, and caused accidents.</p>
  
  <p>Then you gave own slide to each of the programs, so that they can play safely, even if they want to slide simultaneously!
  <a href="https://i.sstatic.net/MuYCD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MuYCD.png" alt="enter image description here"></a></p>
  
  <p>You can use aquapark water slides instead if you think that the normal ones are not convincingly dangerous.</p>
  
  <p><sup>* Perhaps these where threads, but I don't think the distinction is important. Better to keep one term.</sup></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-24T00:59:18.353Z
Answers.LastActivityDate: 2018-10-24T00:59:18.353Z
Answers.UserDisplayName: Frax
Body: <p><strong>TL;DR: How would you explain what is a race condition to a five years old. Which analogy to concepts he is familiar with would you use?</strong></p>
  
  <p>Long version:
  I am not a teacher but a software engineer. Yesterday evening, while discussing what the day was like with my five years old son I told him that I worked on an annoying bug, that ended up being caused by a race condition. He then asked me what a race condition is.</p>
  
  <p>I tried to explain the concept to him by making the analogy with multiple people all writing a story on the same blackboard. If they all write their story at the same time then one person might start writing over part of a story already written by someone else.</p>
  
  <p>However I think that this analogy was probably not the best because he then asked me which person did “won”. I explained to him that nobody did win because the end result was that the “story” that was written on the blackboard was not making any sense. </p>
  
  <p>He then asked me how did I solved the problem and I told him that I did give each story writer his own blackboard.</p>
  
  <p>So I am looking for a good way to explain what is a race condition to a five years old, ideally without using a programming terminology because that would mean nothing to him.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-20T23:49:49.443Z
Comments.Text: Just tell them that it is caused by **shared mutable state**. The pain of doing this will help you to re-consider your design.
Comments.UserDisplayName: ctrl-alt-delor
Tags: <lesson-ideas>
Title: How would you explain what is a race condition to a five years old
ThreadText: # How would you explain what is a race condition to a five years old
  
  (Asked by: username_0 on 2018-10-04)
  
  **TL;DR: How would you explain what is a race condition to a five years old. Which analogy to concepts he is familiar with would you use?**
  
  Long version:
  I am not a teacher but a software engineer. Yesterday evening, while discussing what the day was like with my five years old son I told him that I worked on an annoying bug, that ended up being caused by a race condition. He then asked me what a race condition is.
  
  I tried to explain the concept to him by making the analogy with multiple people all writing a story on the same blackboard. If they all write their story at the same time then one person might start writing over part of a story already written by someone else.
  
  However I think that this analogy was probably not the best because he then asked me which person did “won”. I explained to him that nobody did win because the end result was that the “story” that was written on the blackboard was not making any sense.
  
  He then asked me how did I solved the problem and I told him that I did give each story writer his own blackboard.
  
  So I am looking for a good way to explain what is a race condition to a five years old, ideally without using a programming terminology because that would mean nothing to him.
  
  **Tags:** lesson-ideas
  
  > **Comments:**
  > **username_1**: Just tell them that it is caused by **shared mutable state**. The pain of doing this will help you to re-consider your design.  
  
  ---
  
  ## 6 answers
  
  ### Answer by username_4 on 2018-10-04. Score: 10 | Accepted answer
  
  A lot of race conditions result from improper or unexpected interleaving of processes. Someone that age can probably understand the fable of the Turtle and the Hare.
  
  Give the Hare a ball with instructions to run to a table, some distance away, and leave the ball on the table and return.
  
  Tell the Turtle to go to the table, pick up the ball, and return with it.
  
  Start the two "running" at the same time.
  
  The Turtle has no instructions about waiting, since the *proper* interleaving is *obvious*.
  
  Of course, if the Turtle gets to the table first then the process fails.
  
  ---
  
  I'll note that [Dining Philosophers](https://en.wikipedia.org/wiki/Dining_philosophers_problem) isn't a lot more difficult than the above, but probably not accessible to a five year old. Certainly open to one a few years older, though.
  
  > **Comments:**
  > **username_5**: How would you modify this to deal with the "sometimes" fails for race conditions?  
  > **username_4**: @username_5, well, sometimes the bunny does, in fact, do the right thing. And sometimes the turtle is the one who wants a nap.  
  > **username_0**: I find the Turtle and Hare comparison really nice as it nicely illustrate that one actor might be “faster” than another one but might take “pauses”. About the Dining Philosophers I would definitely use it to illustrate what a deadlock might be, however I do think that the associated concepts might be a bit difficult to explain to a kid of that age (who would need two forks to eat??? ;) )  
  > **username_6**: @RenaudM., the dining philosophers problem makes more sense if the table is set with _chopsticks_  instead of forks.  
  > **username_7**: 5 year olds love the stacking hands game, where the players interleave their hands in a stack, then each player when his hand is one the bottom of the stack pulls it out and places it on the top of the stack. The players get faster and faster until there is just crazy slapping as everyone's hands collide. That is a race condition.  
  
  ---
  
  ### Answer by username_8 on 2018-10-23. Score: 6
  
  Imagine two guys at a door. Each says, "No, you go first." Result: deadlock.
  
  > **Comments:**
  > **username_5**: Simplicity itself.  
  
  ---
  
  ### Answer by username_9 on 2018-10-05. Score: 2
  
  Musical chairs where one person sits on another as they are both going for one of the last chairs — this is comical, though in seriousness, clearly a less than desirable seating arrangement.
  
  > **Comments:**
  > **username_4**: Pretty close, except that "everyone sitting" is guaranteed to fail here. Instead, have a second "process" remove a chair after the music starts. If the music stops early, everyone sits, otherwise the usual thing. Even this is a bit suspect as one of the two processes (circling, removing) will always fail.  
  
  ---
  
  ### Answer by username_10 on 2018-10-24. Score: 2
  
  When there is a slide in the playground where many children want to slide, they need to queue and each one needs to check if the slide is free (i.e. if the previous child got up from the bottom of the slide) before going down. If they don't check it, they may run into one another and hurt themselves.
  
  That is what happened to your programs\* - some where playing carelessly, and caused accidents.
  
  Then you gave own slide to each of the programs, so that they can play safely, even if they want to slide simultaneously!
  [![enter image description here](https://i.sstatic.net/MuYCD.png)](https://i.sstatic.net/MuYCD.png)
  
  You can use aquapark water slides instead if you think that the normal ones are not convincingly dangerous.
  
  \* Perhaps these where threads, but I don't think the distinction is important. Better to keep one term.
  
  
  ---
  
  ### Answer by username_2 on 2019-09-10. Score: 1
  
  I would use the nursery tale of two goats across a narrow bridge. Once the first goat is on the bridge, the second one needs to wait before getting on the bridge till the first has crossed over, so as to avoid a collision. That is also why road workers use flags also called semaphores to coordinate traffic on lane closures.
  
  
  ---
  
  ### Answer by username_3 on 2019-09-10. Score: 1
  
  I think a case that hasn't been covered yet is the possibility of work being completed twice or work being lost due to a race condition. Here is an example to fill that gap:
  
  You have 2 groups of dogs, the "carriers" and the "pick up-ers". They are on opposite sides of a field, and in the middle is a small cup, which only one ball can fit on top of. The carriers have a pile of tennis balls, and have been trained to bring the balls to the cup. The pick up-ers have been trained to take a ball out of the cup and bring it back to their side. You are watching this happen and counting the number of balls that have been brought over by counting the dogs-with-balls-in-their-mouths that reach the pick-up-ers side.
  
  What happens if two carrier try and put a ball in the cup at the same time? One will fall on the ground, and won't get picked up, causing you to lose that tennis ball. Or what if two pick-up-ers try and grab the same ball and both grab it together? You'll count it as two, since two dogs-with-balls-in-their-mouths crossed the finish line, but actually only one ball has been carried.
  
  
  ---
  
  