What my dog taught me about race conditions

I have a black Labrador named Sofie. She's about 2 and a half now, but still a puppy at heart. Here's a picture of her (along with her best friend, Sierra, who is a yellow lab):

One morning, Sofie reminded me of a valuable issue with threading and race conditions.  Our morning ritual for feeding is that Sofie starts dancing out of anticipation for breakfast (literally - fellow dog owners know what I mean), which usually involves her jumping up and down and chasing her tail in circles.
I then tell her to "sit" and then "stay", which means she's supposed to be stationary and not move until I say "OK". I then proceed to get her food, fill her dish, and wait a minute to reinforce her discipline. I then say "ok" and she rushes to her food dish and enjoys the life of a dog.

So what's the lesson?
One morning we came down, and instead of dancing, she just sat down and waited. So I proceeded to fill her dish ... and then she immediately ran and ate the food. I realized that because she was already sitting, I never issued the "sit" and "stay" commands.  To be more technical: Sofie and I each represent a thread, and her being in a "sitting" state lulled me into a false sense of security where I got lazy and avoided uses the synchronization primitives. Thus she was not ordered to wait and free to eat her food at her convenience.

Comments (9)

  1. Hehe. Thats a nice story. I would have just thought that your dog managed to circumvent the norm (its a hacker at heart) 🙂

  2. Scott says:

    Think what might have happened if the thread had been running with administrative rights!

  3. Майк Сталл — создатель компилятора C#, написанного на C# — рассказывает о пробле

  4. Can somebody translate the comment that’s not in english?

  5. Long live Babelfish. 🙂

    Here’s its translation.

    "Mayk Stull [should be Mike Stall] – creator of compiler C #, written on C # – he tells about proble"

    Seems like its a trackback.

  6. gaidar says:

    By the way, Oleg Mihailik wrote that kind of your dog is the same as Russian President Vladimir Putin’s dog.


  7. My 19-month old daughter was quite the finite state machine today.

    She’s recently become mobile and…

  8. My wife + I recently had daughter #2. I’m taking time off, and so my participation on the forums and

Skip to main content