Test-and-set
Lock is a memory location that contains 0 or 1
Test-and-set (attempt to acquire) writes a 1 and returns the value in memory
If the value is 0, the process gets the lock; if the value is 1 another process has the lock.
To release, just clear the memory location.
Atomic-swap is a generalization of Test-and-set that allows values besides 0 and 1
Compare-and-swap is a further generalization: the value in memory is not changed unless it is equal to the test value supplied