0

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.

Zoolander
  • 53
  • 4

1 Answers1

0

On preemptive multithreading systems, other processes are allowed to run between TestAndSet==false and skip as well as between skip and TestAndSet. So it works on single core systems as well.

D.R.
  • 20,268
  • 21
  • 102
  • 205