I am reading some material on test and set instructions from Wiki(https://en.wikipedia.org/wiki/Test-and-set)
What i understand is most CPUs support a special instruction "test and set" to achieve mutual exclusion. However I do not understand is the it talks about CPU spinning to acquire a lock. Can this be implemented on single core systems. If yes then spinning to acquire the lock do not make sense to me. Or may be I am missing the point where test ans set instruction is only possible on multiple core systems?
boolean lock = false
function Critical(){
while TestAndSet(lock)
skip // **spin until lock is acquired**
critical section // only one process can be in this section at a time
lock = false // release lock when finished with the critical section
}
Thanks in advance for your feedback.