Semaphores for children

In the never ending search for better metaphors, I stumbled upon a nice example from my childhood. When I was a child and went to kindergarten, next to the door in the classroom, there were 2 necklaces. If you wanted to go to the toilet, you had to take a necklace, and when you returned, you had to put the necklace back. If you were unlucky, both necklaces were lent, and you had wait or try again a few minutes later. This is a perfect example of a Semaphore with 2 licences.

The solution isn’t quite optimal however. The building has room for 2 classrooms (with each 2 necklaces) and 4 toilets. So it could happen that a child needs to wait in one classroom, even though the necklaces in the other classroom still are available. But heck, what more can you expect from a child that is able to comprehend the basic concepts of concurrency control 🙂


Leave a Reply


WordPress.com Logo


Twitter picture


Facebook photo


Google+ photo


Connecting to %s

%d bloggers like this: