An image of hundreds of locks placed on a bridge in Paris to symbolize love

The Lock—Extraordinary Ordinary Things

A major hit song of the 1960s, in fact, now considered to be a classic, is Roger Miller’s 1966 rendition of “King of the Road,” lauding the freedom of being a drifter, working only when necessary, and constantly moving on. Everything leads the listener to believe the singer is an honest person with minimal wants and needs. However, at one point he informs us:

I know every engineer on every train
All of the children and all of their names
Every handout in every town
Every lock that ain't locked when no one's around.

The last line appears quite ambiguous. I have never quite understood how to interpret it because it seems so out of character with the rest of the song. I would really like to know.

However, what is certainly not ambiguous or open to question is the important roles the lock has played in defining and shaping human society. Indeed, for some, it is virtually the quintessential dividing line between city folks, i.e. those who lock their doors, often with multiply locks, for fear of unwanted intrusions, and country folk, i.e. those who don’t lock their doors because they feel there is no need to. “Everyone knows everyone, so we are certain no one is going to do anyone any harm.”

The lock symbolizes this fundamental cleavage in how people view and interact with each other. If this were its only claim to fame, it would certainly merit respect as one of the most important invents in human history. However, its influence extends into numerous other areas. Thus, I feel it fully justified to give the lock a place of honor on the list of what I like to call “extraordinary ordinary things.”

What Is a Lock?

The word “lock” has a variety of definitions. Here are the most common.


  • A restraint incorporated into the ignition switch to prevent the use of a vehicle by persons who do not have the key.
  • An enclosure consisting of a section of a canal that can be closed to control the water level; used to raise or lower vessels that pass through it.
  • A mechanism on a canal to raise and lower ships by allowing water to flow in or drain out of an enclosed space where the ship is located.
  • A mechanism that detonates the charge of a gun.
  • Any wrestling hold in which some part of the opponent’s body is twisted or pressured.


  • Fasten with a lock. Example: “Lock the bike to the fence.”
  • Become rigid or immoveable. Example: “The therapist noticed that the patient’s knees tended to lock during this exercise.”
  • Hold in a locking position. Example: “He locked his hands around her neck.”
  • Hold fast, be imprisoned by. Example: “He was locked in a laughing fit.”
  • Become engaged or intermeshed with one another. Example: “They were locked in embrace.”
  •  Put in a place where something cannot be removed or someone cannot escape. Example: “The parents locked her daughter up for the weekend.”

In this blog, I am going to lock in on the definition that probably most often comes to mind when the word “lock” is mentioned, i.e. a fastener fitted to something to keep it firmly closed.

Locks used for fastening are commonly divided into two essential categories: 

  • Fixed lock. This is a lock directly built-in or permanently attached to the object it is designed to protect, such as the lock on the front door of one’s house or apartment.
  • Portable lock. This is a lock that is independent of the object it is designed to protect, i.e. it can be completely removed and brought out again only when needed. 

Professionals define numerous types of portable locks, the  most common being the almost ubiquitous “padlock.”  Structurally, a padlock consists of a block of metal plus a U-shaped bar (“shackle”) attached to the block. One end of the shackle is permanently affixed to the block while the other end remains free. The lock is closed by inserting the free end of the shackle into the block. It is opened by using a key or a code (combination of numbers) to release it. I once had a particularly bizarre experience with a combination padlock.

Shortly after moving to Brussels (I grew up in Los Angeles), for my work I needed an authentic Yale padlock. I went to a branch of a national chain of hardware stores and searched the lock section for a Yale padlock, but found none.

I asked a shop assistant, “Don’t you carry Yale locks?”

“We used to,” he replied. “But we stopped because they didn’t work.”

I was stunned. Yale was generally considered the epitome of combination locks.

“They didn’t work? A Yale lock?” I exclaimed. He nodded. “But I really need a Yale lock. Do you know where I might find one?”

He said that there may still be some in the stockroom. He went to look and came back with a genuine Yale lock.

“May I try it?” I asked. He assented.

I opened the package and read the instructors. Being Belgium, they were in English, French, and Dutch. Following the instructions in English, I was able to easily open and close the lock. I then decided to try it with the instructions in French, and indeed it didn’t work. Then I tried the instructions in Dutch; once again it didn’t work.

An error had been made in translating the instructions from English into both French and Dutch. So the locks were withdrawn in all the from the companies branches all across the country. There is an expression (often quoted in Latin) that cautions “translation is treason.”  In Belgium, Yale learned this lesson very much to its chagrin—and significant financial loss.

History of the Lock

The lock has traced a long and noble path, dating back to prehistoric days. Here is a very brief overview of key developments along the many millennia of the lock’s epic journey.

While many people may automatically associate the concept of the lock with some kind of punishment, e.g. prison, handcuff, ball-and-chain, etc., people who study such things would argue otherwise.The lock is an outgrowth of what many would argue is a key aspect of human beings: the need to possess and protect what we consider to be our own property. In other words, since prehistoric days, even when the clan or tribe was all-pervasive, we already felt the need to possess (even if only to a very limited degree) some things that were reserved for use along. The direct concomitant of the idea of personal property is the need to protect that property from predation by others.

In the earliest of days of human history, this was done largely by intricately tying ropes into knots to keep things hidden away and safe. But as time went on (and presumably the idea of personal property gained greater and greater traction), such simple protective measures became inadequate. Enter the lock. Although the concept of “technology” probably didn’t exist at the time, the lock was definitely a new technology that was a startling improvement over previous technologies.

The oldest known lock dates some 4,000 years and was found in ruins near Ninevah, the capital of ancient Assyria, a Mesopotamian kingdom and empire of the ancient Near East. Extremely simply, this lock consisted essentially of a slab of wood that fitted into a slot. It is likely that even older locks existed but may have been overlooked by archeologists who simply didn’t recognize what they were.

The earliest known lock and key device was discovered in the ruins of Nineveh, the capital of ancient Assyria. Around 3,000 years ago, locks such as this were developed into the Egyptian wooden pin lock, which consisted of a bolt, a door fixture or attachment, and a key. When the key was inserted, pins within the fixture were lifted out of drilled holes within the bolt, allowing it to move. When the key was removed, the pins fell part-way into the bolt, preventing movement. Their locks and keys were very large, requiring a grown person to open and close them. They were exclusively used to secure doors to prevent unauthorized people from gaining access to what was behind the doors.

It wasn’t until the Roman Empire that locks really began to shine. Building on Greek designs, the Romans introduced metal to lock construction, making them far stronger and better able to protect valuables. The Romans were also able to shrink the size of the locks and keys such that the key became much easier to keep close at hand rather than storing it and having to go get it when needed. These smaller keys became somewhat of a fashion accessory.  Many wealthy Romans would wear their keys as jewelry as a sign of their affluence.

After the fall of the Roman Empire (5th century CE), the development of locks largely ground to a halt. In fact, the next major advance in lock technology had to wait until the 18th century, more than a thousand years later.

It was only in 1778 that Englishman Robert Barron designed and built the first double-acting tumbler lever lock. This device featured a lever with a slot cut into it. It worked by lifting the lever to a specified height; lifting the lever too far was as bad as not lifting it far enough. The principles on which it was built still influence lock designs today.

In 1784 fellow Englishman Joseph Bramah from Barnsley designed and built what was billed as an “unpickable lock,” i.e. a lock that no one could open without the accompanying authorized key. It maintained its reputation for being unpickable for 67 years before someone successfully found a war around its safeguards.

In 1818 Englishman locksmith Jerimiah Chubb (1779–1845) designed the Chubb detector lock. This was a type of lever lock that contained a “re-locker” that would jam the lock if any unauthorized person attempted t open it. It was only by inserting the original key that the lock could be reset.

The final notable advance in fundamental lock technology occurred in 1848 when American locksmith Linus Yale (1797–1858) developed the first pin tumbler lock. The pin tumbler design used pins of varying lengths to prevent the lock from being opened without the correct key. The Yale Lock Manufacturing Company later became famous (in fact became the reference) for its non-key combination padlocks, which led to the odd adventure I had trying to procure a Yale padlock in Belgium, as described above.

Thus, by the middle of the 19th century, the fundamental principles of locks had been laid down and had become firmly established. Even today’s supersophisticated electronic locks, voice recognition locks, visual recognition locks, etc., still operate on these same basic principles.

Idioms with Lock

The lock has given rise to an enormous number of idioms (idiomatic expressions). While most of these refer to the lock as a device for securely shutting something away, many do not. Here are some of the most common ones (there are many more).

Locksmith. A person who makes or repairs locks. The word is a combination of lock + smith. “Smith” is a general term for a maker of something, such as a blacksmith or a gunsmith

Lock art. Art displayed in a public space, typically attached to a fence or street lamp, without permission. Also known as street art.

Lockup. A jail or prison

Lock up, lock away. Protect something by putting it in a safe place secured with a lock. Also, to temporarily close something such as a business establishment. Example: “Let’s lock up and go home for the evening.”

Lock down. Shut down, stop from functioning. This expression should need no explanation, having been the leitmotif of people around the world since the beginning of 2020 due to Covid-19

Pick a lock. Open a lock by using something that is not the key or combination. Example: “The burglar picked the lock to open the safe and steal the jewels.


  • An intermediate chamber with two airtight doors or openings to permit passage between two dissimilar spaces such as two places of unequal atmospheric pressure. Airlocks are quite familiar to science fiction fans as being the means of passing from one spaceship to another.
  • A stoppage of flow caused by air being in a part where liquid ought to circulate.

Vapor lock. Partial or complete interruption of the flow of a fluid (such as fuel in an internal combustion engine) caused by the formation of bubbles of vapor in the feeding system

Dreadlocks. Rope-like strands of hair formed by locking or braiding the hair. Dreadlocks differ from braids in that braids can be prepared immediately whereas dreadlocks require a period of maturation to achieve the desired effect.


  • A traffic jam in which a grid of intersecting streets is so completely congested that no vehicles can move.
  • A situation resembling gridlock, i.e. an impasse. Example: “There is now complete gridlock between the executive and legislative branches of government.

Hammerlock. A wrestling hold in which an opponent’s arm is held bent behind the back broadly. By extension, any situation in which someone is clearly in a dominant position, e.g. “Jane has a hammerlock on winning the contest. No one can catch her.”

Lip lock (to lock lips). A long, languorous kiss (to engage in a long, languorous kiss).


  • A symptom of tetanus, a spasm of the jaw muscles causing the mouth to remain tightly closed
  • An accent associated with the upper class of the north-eastern United States, characterized by a supposed lack of movement of the mouth and jaw.

Wedlock. The state of being locked together in marriage.


  • A way of marching with each person as close as possible to the one in front. close adherence to and emulation of another’s actions. To be in lockstep means to be in perfect, often mindless, conformity or unison.
  • In dancing, Lockstep refers to any of several dance steps that involve the “locking” of the moving foot: the moving foot approaches to the standing foot, crosses in front of or behind it in the direction of the approach, stops close to the standing foot, and the weight is fully transferred to the (previously) moving foot.

Lock horns. Come into conflict, as in animals who do battle by attacking with their horns, e.g. deer, moose

Lock into. Come to a firm agreement destined to last a long time and from which the agreeing parties cannot easily withdraw. Ensnare in a situation, usually against one’s will, from which it is difficult if not possible to disentangle oneself.

Lock on to:

  • Become able to automatically track and target someone or something, such as a guided missile first locks on to its target before it is fired.
  • Fix one’s gaze onto someone or something; to intensely stare at someone or something.
  • Physically attach, fasten, or grab onto someone or something

Locked and loaded. Ready to go, ready to take action. The term derives from riflery where it means locking the magazine or cartridge into the gun and loading the ammunition into the gun’s chamber.

Lock, stock, and barrel. Including all or every part of something. Example: George decided to leave his home lock, stock, and barrel and go live in another country. The term derives from the three principal parts of a gun, i.e. the lock, the stock, and the barrel.

Under lock and key. Safely put away. The term is used both positively and negatively:

  • “He put the government bonds under lock and key.”
  • “The suspect was put under lock and key to await trial.”

For even more uses of the word lock (and there is a lot of them), go to RhymeZone.

“Lockdown” in Different Tongues

Lockdown. This common word has taken on an eerie familiarity in this era of the COVID-19 pandemic. In this context, it means encouraging or requiring people to stay at home except for essential or urgent circumstances. Likewise, it means the enforced closing of a wide variety of businesses deemed to be “non-essential.”

Here I would like to mention how this word has been translated into other languages where it does not always easily translate, which may be a surprise to people who speak only English. This is an aspect of the pandemic that many readers may find interesting, surprising, and even amusing.

While the term “lockdown” seems perfectly appropriate in English, in many languages no directly equivalent word exists, so they either have had to adopt the English word or find other words to express the frightful meaning. For example, German and Italian have taken on the English term, talking about “Det Lockdown” and “Il Lockdown.”

In a moment we will look at some of the interesting and curious ways other languages have expressed the concept. But first some interesting facts about the word lockdown in English.

In 2020 lockdown was named “word of the year” by the Collins Dictionary, which had noted a 6,000% (six-thousand percent) increase in its use. The dictionary defines lockdown as “the imposition of stringent restrictions on travel, social interaction, and access to public spaces.”

While lockdown may have recently evolved this new meaning, the word has several other meanings that are still in the language. For example, in the 1970s lockdown was commonly used to describe extended times of isolation for inmates in psychiatric hospitals or prisons. Lockdown is also used to describe when buildings or areas are closed for reasons of safety, such as the area around the collapsed Champlain seafront condominium in Surfside, Florida (June 2021).

With regard to COVID-19 in other languages, German and Italian chose to adopt the English term, i.e. “der Lockdown” (German) and “il lockdown” (Italian), “det” and “il” being the German and Italian words for “the.”

French chose to go in quite a different direction. In French, lockdown = confinement. I live in Belgium, where French is one of the three national languages. When I first heard the term “confinement” to mean lockdown, I was somewhat taken aback. It just did seem to have sufficient gravitas for the purpose. However, once I began to hear it over and over again, my reticence melted away. I now react to confinement the same way as I originally reacted to lockdown.

Portuguese and Spanish went the way of French, with Portuguese using the term confinamento and Spanish confinamiento. Similar to the French confinement, the Portuguese and Spanish words lean on the idea of being confined or shut away.

Further afield, the Farsi word لی (pronounced Ta’tin) for lockdown is the same as holiday or vacation. It derives from an Arabic root which means idleness, rest, or to be put out of action.

In Hindi, many people use the word लॉकडाउन, whose pronunciation is very close to the English word lockdown. Another commonly used word for lockdown is बंद, pronounced bandh.

Urdu uses the transliterated word لاک ڈاون which, using the Urdu alphabet, is about as close as the language can get to saying lockdown. Another less commonly used word for lockdown is تالا بندی  (pronounced taala-bandi), which literally means “close the gates.” 

In Hebrew,  the word isסגר (pronounced seger), which means a curfew or closure.

The Arabic wordحج ر (pronounced hajr) commonly used for lockdown derives from حجر صحي (hajr sihi), which literally means “health quarantine.”

In Mandarin, the word for lockdown is 封锁 (pronounced fēngsuǒ), which means blocking or blockading, and is often used to refer to “coercive force to sever contact with the outside world.” Given the strict lockdown measures China took from very early on in the pandemic, the word would seem to be particularly appropriate.

Fun Facts about Locks

Locks protect our valuables, secure our homes, fortify our businesses, safeguard our recreation, etc. Anything that has become such a staple of daily life is bound to have a number of interesting, and sometimes even bizarre, aspects to them. And the lock is no exception. Here are a few examples.

  1. The largest padlock ever invented, recognized by the Guinness Book of World Records, is located in the Pavlovo Arts College in Nizhny Novgorod, Russia. The lock and key together total 415 kilograms (916 pounds). The lock itself measures some1.42 meters) tall and 1.04 meters wide.
  2. Lovelock. In many cultures, locks are symbolic of love and marriage (wedlock). But how they are displayed is not always appreciated. For example, in France, the Pont des Arts bridge in Paris had been a destination of lovers for years. Over time, hundreds of thousands of locks had been attached to the bridge’s grillwork, serving as a testament to each couple’s devotion to each other. At one point, it was estimated that there were over a million locks affixed to the bridge, weighing an estimated 45 tons. The weight being deemed to threaten the bridge’s structure, in 2015 locks on the bridge were banned. Nevertheless, the practice still continues in many other parts of the world.
  3. Skeleton key.  Also known as a “master key” or “passkey”, this type of key is capable of opening and closing a number of different locks. The origin of the term “skeleton” is not really known; however, it probably derives from the fact that such keys are generally stripped down to their absolutely essential parts, suggesting a skeleton unadorned with flesh. Locksmiths use skeleton keys to open locks when the authorized keys have been lost, stolen, or misplaced.
  4. Ceremony of the Keys. This is a cherished tradition at the Tower of London (United Kingdom). Every evening at precisely 21:52 hours (9:52 p.m.), guards ceremoniously lock the towers (the Tower of London actually consists of more than one tower). The keys are escorted back to the Queen’s residence by the Escort to the Keys. The ceremony has been held nightly since at least the 14th century. It has been delayed only once, during the Second World War. It has never been canceled.
  5. France’s King Louis XVI (1774–1792) was fascinated with locks. He made locks for the pure enjoyment of it and sometimes fashioned locks to use on furniture, such as small chests. He had a forge in his Versailles apartments and was mentored by professional locksmith François Germain, who later betrayed him during the French Revolution.
  6. Russia’s Catherine the Great (1762–1796) was another 18th-century monarch fascinated by locks, possessing one of the most elaborate collections of locks known in her time. She was particularly fond of the intricate designs featured on many locks and often had such locks created to give as gifts.
  7. In an effort to prevent thieves from picking locks, locksmiths in the 19th century were in constant competition to create more complex, secure locking mechanisms. Englishman Jeremiah Chubb succeeded. His groundbreaking idea was to create a locking mechanism with a “relocker.” Thus, if anyone tried to pick the lock, the lock would jam until the original key or a special regulator key was inserted. Chubb invented his lock in 1818, which was considered to be unpickable until American locksmith Alfred Charles Hobb found a way around it in 1851, some 33 years later. At about the same time, Chubb invented his own protector lock which required the transfer of pressure from the lock’s internal mechanisms to a fixed pin before it opened. Somewhat ironically, Hobb’s invention was successfully picked in 1854— by an employee of Jeremiah Chubb.
  8. The Federal Reserve Bank of New York holds and protects gold bars in the basement of its Manhattan offices. Built in the 1920s, the vault is secured by an 82,000 kilogram, 2.75-meter tall steel cylinder guarding the only entrance. The cylinder is located within a 127,000 kg steel and concrete frame that is airtight and watertight. Once sealed, the frame is secured with four steel rods before a time-delayed locking mechanism is engaged. Each gold-containing compartment inside the vault is secured by a key padlock, two combination locks, and an auditor’s seal.
  9. In like manner, Fort Knox (Kentucky) is the storage facility for the gold bullion and reserves of other precious metals of the United States federal government. Arguably America’s more secure building, Fort Knox’s various security measures are shrouded in mystery. What is known about the building is that the front door can be accessed only by designated staff according to random schedules. The staff member must each enter a different combination code to unlock the door, the codes being changed daily.
  10. People who like the challenge of the iconic Rubik’s cube probably would also be tempted by the challenge of “puzzle locks.” These devices require the user to find the hidden trick to open them. Some puzzle locks look deceptively like normal padlocks while others are actually chests or containers whose puzzle lock mechanism must be conquered before they will reveal their contents.
  11. If you think about it for a moment, it should come as no surprise that the famous Hungarian-born American escapologist Harry Houdini (1874-1926) started his career as a locksmith. Young Houdini became an apprentice in a locksmith’s shop at age 11, quickly learning how to pick any lock currently available. He then went on to become one of the most renowned stage performers in the world. His name has become synonymous with getting out of seemingly impossibly difficult situations. For example, “I don’t how George is going to get out of this. He would have to be a regular Houdini.”

Quotations About Locks

You can often gain unexpected insights into a topic by looking at what people say about it. Here are a number of pithy quotations about locks that prove the point.

“A soulmate is someone who has locks that fit our keys, and keys to fit our locks.”—Richard Bach

“I have six locks on my door all in a row. When I go out, I lock every other one. I figure no matter how long somebody stands there picking the locks, they are always locking three.”—Elayne Boosler

“Preconceived notions are the locks on the doot to wisdom.”—Mary Browne

“The instinct of nearly all societies is to lock up anybody who is truly free. First, society begins by trying to beat you up. If this fails, they try to poison you. If this fails too, the finish by loading honors on your head.”—Jean Cocteau

“Too often, the opportunity knocks, but by the time you push back the chain, push back the bolt, unhook the two locks, and shut off the burglar alarm, it’s too late.”—Rita Coolidge

“Wordplay hides a key to reality that the dictionary tries in vain to lock inside every free word.”—Julio Cortazar

“Too many locks, not enough keys.”—Sarah Dessei

“When two friends part they should lock up each other’s secrets and exchange keys. The truly noble mind has no resentments.”—Diogenes

“We spend our life building higher fences and stronger locks when the gravest dangers are already inside.”—Richard Paul Evans.

“Prayer: the key of the day and the lock of the night.”—Thomas Fuller

“Gold opens all locks, no lock will hold against the power of gold.”—George Herbert

Just a simple choice, right now, between fear and love. The eyes of fear want you to put bigger locks on your doors, buy guns, close yourself off. The eyes of love instead see all of us as one.”—Bill Hicks

“Instead of giving a politician the keys to the city, it might be better to change the locks.”—Doug Lanson

“If hard work is the key to success, most people would rather pick the lock.”—Claude Maxwell MacDonald

“Any time you see signs or labels added to a device, it is an indication of bad design: a simple lock should not require instructions.”—Donald A. Norman

“Passion and desire bind your Heart. Remove the locks. Become a key, become a key . . .” —Rumi

“My heart to you is given: Oh, do give yours to me; We’ll lock them up together, And throw away the key.”—Arthur Frederick Saunders

“Tis in my memory lock’d. And you yourself shall keep the key of it.”—William Shakespeare

“Prejudice locks the mind. Nothing can enter. Nothing true can escape.”—Gerry Spence

“Fear is the lock and laughter is the key to your heart.”—Stephen Stills

“The only difference between the sane and the insane is the sane have the power to lock up the insane.”—Hunter S. Thompson

“Isn’t it interesting that we place deadbolt locks on our doors to keep evil influences out, and then allow and even invite evil influences into our home through televisions?”—Randall Wright.

“A man who is ‘of sound mine’ is one who keeps the inner madman under lock and key.”—Paul Valery

“To the optimist, all doors have handles and hinges; to the pessimist, all doors have locks and latches.”—William Arthur Ward

“The doors of Hell, insofar as they have locks, have locks on the inside.”—Kallistos Ware

“Unscrew the locks from the doors! Unscrew the doors themselves from their jambs!”—Walt Whitman

“Philosophy is like trying to open a safe with a combination lock; each little adjustment of the dials seems to achieve nothing. Only when everything is in place does the door open.”—Ludwig Wittgenstein

“Lock up your libraries if you like; but there is no gate, no lock, no bolt that you can set upon the freedom of my mind.”—Virginia Woolf

For a treasure trove of other lock quotes, visit AzQuotes.

Locks and Computing

Already as soon as you approach a computer, before turning it on or looking inside, you encounter locks.

Exterior locks

On the keyboard you will find at least the following three:

  • Num lock. The num lock key allows you to use the numbers on the numeric keypad. When num lock is enabled, to write a number you simply press the number on the numeric keypad rather than having to use a combination of keystrokes.
  • Caps lock. This key allows you to switch the letters you are typing from lower case to upper case. This means that every letter you type will be capitalized rather than having to individually capitalize each letter one at a time. This can be an extremely useful facility, especially for writing angry Twitter messages which, as everyone knows, must be all caps in order to convey the proper sense of outrage. 
  • Scroll lock. This key was initially intended for use to scroll through the contents of a text box. Today, it is particularly useful for working in spreadsheets.

Interior locks

For those who look inside, such as computer professionals, the term “lock” has a number of fundamentally deeper meanings. These fall into two basic categories.

  • Physical locks

A physical lock is a physical device affixed to a computer with an accompanying key used for access control or as an anti-theft system.

In the 1980s, IBM and some PC compatibles included a tubular pin tumbler lock on the computer’s casing to perform a variety of security functions; which differed according to the manufacturer. In some instances, the lock was designed to prevent the case from being opened to inhibit theft or modification of internal components. In other instances, the lock was used to forbid unauthorized use of the computer by disabling the power supply, hard drive, or keyboard.

However, computer locks to prevent theft are still very much with us. Most commonly, these are in the form of a special type of lock (Kensington lock) that attach cables to laptop PCs and small desktop PCs to prevent them from being physically stolen.

  • Software locks

In software, the term “lock” can refer to encryption of data or to synchronization in an operating system. For encryption, the plaintext is locked up behind a code that can be deciphered only by someone with the proper key. For the operating system, a lock is a variable used to prevent more than one concurrent process from executing a critical section of code at the same time.

As indicated above, physical locks are “surface,” i.e. they are on the outside of the computer such as on the keyboard or the desktop. The internal locks are for encryption and synchronization. However, all locks serve the same essential purpose—to prevent the computer’s resources from being used until it is safe to do so.

Start with encryption. Sensitive data can be protected from prying eyes by hiding it behind a code. The resulting cipher can be unlocked only by someone with the proper key. Encryption is widely used on the internet to maintain the privacy of data and security of financial transactions. Public key encryption, which uses one key to lock and a second key to unlock, is also used for authentication because one of the two keys is always exclusively linked to a particular person (that person’s secret key). This form of encryption is used in the internet protocols for mutual authentication of machines.

Next, consider software locks. From early days, CPUs contained a test-and-set-lock instruction (TSL) that used a memory location as a lock.  Designers early on recognized that blocks of code and data might have to be locked while they were being used. Thus if x is the lock, and 0 means unlocked and 1 locked, TSL(x) in one memory cycle returns the value of x and sets x=1 (locked). If the CPU needs to pass a lock point, it uses the TSL(x) to find out if it can pass. Once finished with its locked task, it needs to set x=0 again so that the next time a CPU comes by it will not get stuck. The protocol is:

While TSL(x)=1 loop

Critical section: something that only 1 CPU can do at a time safely


When databases were being built, it was essential to lock account records while they were being used in order to prevent multiple users from interfering. For example, at an ATM, if I want to transfer $100 from account A to B, I need to lock both accounts before subtracting 100 from A and adding 100 to B. Proper locking of records is a large part of database design theory.

The idea of a semaphore was introduced (Dijkstra c.1965) as a generalized software lock. It was designed to make a CPU stop instead of wasting cycles spinning in a lock-testing loop.  A semaphore s contains both a counter and a queue and can be accessed with two operations.

WAIT(s) subtracts 1 from the counter and if it is negative puts the caller in the waiting queue. SIGNAL(s) adds 1 to the counter and if it is non-negative releases one waiting process from the queue. As long as the initial counter is 0 or larger, a negative count tells you how many processes are waiting.   Now the critical section protocol becomes


Critical section


Where initially count(s)=1.

This use of a semaphore is called mutual exclusion and the semaphore itself is often called “a mutex”.

Locks, therefore, are essential for building the most common applications where resources are shared and must be locked while in use. Interestingly, the existence of processes waiting for locks creates the possibility of another kind of lock, the deadlock, which is a circular wait among processes. Two or more processes can be stuck in a cycle, each waiting for the next to release a lock—but that will never happen because they are all locked. 

An example from banking is how ATM implements a transfer of funds from one account A to another B:


Lock A

Lock B

Transfer X from A to B

Unlock B

Unlock A

If joint account holders Alice and Bob arrive at different ATMs simultaneously to make a transfer in opposite directions, Alice will ask for the locks in the order A, B while Bob is asking for them in the order B, A. However, in such a case Alice can lock A at the same time Bob locks B.  This means Alice waits for B and Bob waits for A.  Neither can do anything. They are frozen in a circular wait state. One way (among others) to prevent the deadlock is to reorder lock requests into a standard order, say alphabetically, so that circular wait becomes impossible.

This example gives an idea of just how fundamentally embedded the concept of locks is to safeguard data that can be accessed in parallel by different processes. They are deep in the design of hardware, software, and programming languages. Every computer science major has to learn about locks and how to use them wisely and well.