What a geeky post title. Well, I guess it's a geeky post.
Based on the number of people actually in the bathroom at work when I'm in there, I would think that two people entering/exiting the bathroom at the same time would be a rare event. Yet, I've come to expect the door to magically open in front of me as my hand nears the handle, or swing violently at my face as I exit.
I always find it amazing the number of things in real life that have dualities in software. In software, we'd solve the problem of collisions in the doorway by taking a lock on it (although locking on a public object is not always a good idea). This becomes a problem in the real world because of visibility. The bathroom door has no window (which is probably good), so you can't see when someone is right on the other side. You seldom have a collision when the door has a window because you can see who else is going to try to use the door before you can get there. There are tons of "shared resources" in the world where we've created synchronization mechanisms of various authority. I think we could learn a thing or two by observing them.
For instance, when roads intersect, we have several different ways of dealing with collisions (we sometimes call them that in the software world as well.):
- Raw intersection - No traffic signs or anything. Typically found on dirt roads where traffic is scarce and the probability of collision is low.
- Yield - One street is a lower priority and "yields" the intersection to the other road.
- Stop signs - you see where I'm going
- Flashing Lights
- Traffic Lights
- Traffic circle - This one always amuses me. It is actually a very efficient means of managing an intersection IF the drivers are familiar with navigating it. If they are not, hilarity ensues.
- Overpass
And there are tons of "in-between" flavors. Hopefully you see what I'm getting at. The granularity of synchronization in software can be just as complex. Simple locks, Mutexes, Reader/Writer locks, etc.
Where am I going with this? I don't know. I just thought it was interesting how many real-world examples of synchronization there are, and how we avoid them in different scenarios, sometimes delegating that responsibility, sometimes taking a more strict position. Prioritizing etc.
That is all.