Busy Waiting with Test-and-Set
A test-and-set instruction provides the atomic guarantees needed to implement critical sections
Boolean Function test-and-set (var target: boolean)
test-and-set := target ; return old value of target
target := true ; set target to true
using test-and-set(initialize aLock:= false at beginning)
while test-and-set(aLock)do no-op ; spin until lock is free (and atomically
<do the critical section>
aLock := false ; free the lock for someone else