...
/Building Working Spin Locks with Test-And-Set
Building Working Spin Locks with Test-And-Set
In this lesson, you will learn the correct implementation of a lock, the test-and-set method.
We'll cover the following...
Because disabling interrupts does not work on multiple processors, and because simple approaches using loads and stores (as you saw in the previous lesson) don’t work, system designers started to invent hardware support for locking. The earliest multiprocessor systems, such as
Test and set
The simplest bit of hardware support to understand is known as a test-and-set (or
int TestAndSet(int *old_ptr, int new) {int old = *old_ptr; // fetch old value at old_ptr*old_ptr = new; // store ’new’ into old_ptrreturn old; // return the old value}
ASIDE: DEKKER’S AND PETERSON’S ALGORITHMS
In the 1960s, Dijkstra posed the ...