When there is a sock on the door knob, this serves as a notification that the people inside this room or apartment are having sex.

Most common in roommate situations where the person you share the house/apartment/dorm/etc with are having sexual relations and request that they be left alone. A sock on the door knob makes a quick and easy 'do not disturb' sign. It also may be used for a reminder of some sort.

If you approach a room with a sock on the door knob (or possibily a rubber band), please please please do not knock or otherwise disturb the occupants. Please do not call the occupants on the phone. They obviously have something better to do than see you. GO AWAY!

A solution to a real life synchronization problem. The doorknob/sock combo is essentially an unenforced mutex object. If a roommate thread violates the mutex, either (linux dorms) the locking thread receives a SIG_COITUS interruptus or (Win98 dorms) the system crashes with an orgy sharing violation (thx m_turner!).

In practice:

Both roommates want some private time in the room, but neither must enter while the other one is busy. When one roommate wants exclusive access to the room, they place a sock on the doorknob. Both are instructed not to enter the room if they see a sock in the door, and to wait until later. The sexiled roommate can check the doorknob at regular intervals or perhaps use exponential backoff timing between checks.

In code (for each roommate thread):
while(testAndSet(sockOnKnob)) {

This is an example of a spinlock using an atomic (uninterruptable) testAndSet() function. It assumes that both roommates are not in the room at the time the algorithm begins. Spinlocks in general are inefficient since the waiting roommate(s) are not doing anything productive while waiting. In a semaphore system, for example, the roommates would have pagers that would allow them to communicate via interrupts.

Log in or register to write something here or to contact authors.