Building a Lock

This lesson gives a brief idea behind building a lock.

By now, you should have some understanding of how a lock works, from the perspective of a programmer. But how do you build a lock? What hardware support is needed? What OS support? It is this set of questions we address in the rest of the lessons in this chapter.

THE CRUX: HOW TO BUILD A LOCK

How can you build an efficient lock? Efficient locks provide mutual exclusion at low cost, and also might attain a few other properties we discuss below. What hardware support is needed? What OS support?

Press + to interact

To build a working lock, you will need some help from your old friend, the hardware, as well as your good pal, the OS. Over the years, a number of different hardware primitives have been added to the instruction sets of various computer architectures; while you won’t learn how these instructions are implemented (that, after all, is the topic of a computer architecture course), you will learn how to use them in order to build a mutual exclusion primitive like a lock. You will also learn how the OS gets involved to complete the picture and enable us to build a sophisticated locking library.

Get hands-on with 1400+ tech skills courses.