244

Toilets and race conditions!

A co-worker asked me what issues multi-threading and shared memory can have. So I explained him that stuff with the lock. He wasn't quite sure whether he got it.

Me: imagine you go to the toilet. You check whether there's enough toilet paper in the stall, and it is. BUT now someone else comes in, does business and uses up all paper. CPUs can do shit very fast, can't they? Yeah and now you're sitting on the bowl, and BAMM out of paper. This wouldn't have happened if you had locked the stall, right?

Him: yeah. And with a single thread?

Me: well if you're alone at home in your appartment, there's no reason to lock the door because there's nobody to interfere.

Him: ah, I see. And if I have two threads, but no shared memory, then it is as if my wife and me are at home with each a toilet of our own, then we don't need to lock either.

Me: exactly!

Comments
  • 57
    Can I please hire you for 'the birds and the bees' talk when the time comes?
  • 2
    I use a similar metaphor but with food. I defo prefer yours. Stealing it. Thanks!
  • 5
    I like this, except I can't imagine how someone can take all of the paper while you are sitting there
  • 6
    @nibor One CPU may wreak more havoc within a blink of an eye than you can repair in your whole life, that's how.
  • 10
    @nibor with a blank face. Staring at you.
  • 3
    @rutee07 you are a colorful person.
  • 3
    Your rants are magical. This belongs in Fast-Nop’s programming explained coffee table book. 👌🏼
  • 4
    @ybautista Btw. operating systems: if you have different processes accessing the same addresses in their repective address spaces, then it's like two people using the same stall, but in different floors of the building. :-)
  • 2
  • 2
    "TOILETS and RACE conditions".

    Oh, lawd. This could have been spicy! :D
  • 2
    I thought this was a joke about indians and streets. Am I closet racist.
  • 2
    Well done sir! Well done 😂
Add Comment