Here's the Test and Set written in software:
boolean TestAndSet(boolean *target) {
boolean rv = *target;
*target = TRUE;
return rv;
}
and
do {
while(TestAndSetLock(&lock))
; // do nothing
// critical section
lock = FALSE;
// remainder section
} while(TRUE);
Can we use the mechanism in CPUs that do not support test-and-set at the hardware level? If so, how is atomicity assured?